@@ -91,45 +91,27 @@ export class ConfigService implements IDisposable {
9191 return false ;
9292 }
9393
94- public getUserServerBinPath ( ) : string | undefined {
95- let bin = this . vsCodeConfig . binPathOxlint ;
96- if ( ! bin ) {
97- return ;
98- }
99-
100- // validates the given path is safe to use
101- if ( validateSafeBinaryPath ( bin ) === false ) {
102- return ;
103- }
104-
105- if ( ! path . isAbsolute ( bin ) ) {
106- // if the path is not absolute, resolve it to the first workspace folder
107- const cwd = this . workspaceConfigs . keys ( ) . next ( ) . value ;
108- if ( ! cwd ) {
109- return ;
110- }
111- bin = path . normalize ( path . join ( cwd , bin ) ) ;
112- // strip the leading slash on Windows
113- if ( process . platform === "win32" && bin . startsWith ( "\\" ) ) {
114- bin = bin . slice ( 1 ) ;
115- }
116- }
117-
118- return bin ;
94+ public async getOxlintServerBinPath ( ) : Promise < string | undefined > {
95+ return this . searchBinaryPath ( this . vsCodeConfig . binPathOxlint , "oxlint" ) ;
11996 }
12097
12198 public async getOxfmtServerBinPath ( ) : Promise < string | undefined > {
122- let bin = this . vsCodeConfig . binPathOxfmt ;
99+ return this . searchBinaryPath ( this . vsCodeConfig . binPathOxfmt , "oxfmt" ) ;
100+ }
123101
102+ private async searchBinaryPath (
103+ settingsBinary : string | undefined ,
104+ defaultPattern : string ,
105+ ) : Promise < string | undefined > {
124106 const cwd = this . workspaceConfigs . keys ( ) . next ( ) . value ;
125107 if ( ! cwd ) {
126108 return undefined ;
127109 }
128110
129- if ( ! bin ) {
130- // try to find oxfmt in node_modules/.bin, resolve to the first workspace folder
111+ if ( ! settingsBinary ) {
112+ // try to find the binary in node_modules/.bin, resolve to the first workspace folder
131113 const files = await workspace . findFiles (
132- new RelativePattern ( cwd , " **/node_modules/.bin/oxfmt" ) ,
114+ new RelativePattern ( cwd , ` **/node_modules/.bin/${ defaultPattern } ` ) ,
133115 null ,
134116 1 ,
135117 ) ;
@@ -138,20 +120,20 @@ export class ConfigService implements IDisposable {
138120 }
139121
140122 // validates the given path is safe to use
141- if ( validateSafeBinaryPath ( bin ) === false ) {
123+ if ( validateSafeBinaryPath ( settingsBinary ) === false ) {
142124 return undefined ;
143125 }
144126
145- if ( ! path . isAbsolute ( bin ) ) {
127+ if ( ! path . isAbsolute ( settingsBinary ) ) {
146128 // if the path is not absolute, resolve it to the first workspace folder
147- bin = path . normalize ( path . join ( cwd , bin ) ) ;
129+ settingsBinary = path . normalize ( path . join ( cwd , settingsBinary ) ) ;
148130 // strip the leading slash on Windows
149- if ( process . platform === "win32" && bin . startsWith ( "\\" ) ) {
150- bin = bin . slice ( 1 ) ;
131+ if ( process . platform === "win32" && settingsBinary . startsWith ( "\\" ) ) {
132+ settingsBinary = settingsBinary . slice ( 1 ) ;
151133 }
152134 }
153135
154- return bin ;
136+ return settingsBinary ;
155137 }
156138
157139 private async onVscodeConfigChange ( event : ConfigurationChangeEvent ) : Promise < void > {
0 commit comments