@@ -28,8 +28,28 @@ export default class LinterTool implements ToolInterface {
2828 // LSP client instance
2929 private client : LanguageClient | undefined ;
3030
31+ async getBinary (
32+ context : ExtensionContext ,
33+ outputChannel : LogOutputChannel ,
34+ configService : ConfigService ,
35+ ) : Promise < string | undefined > {
36+ const bin = configService . getUserServerBinPath ( ) ;
37+ if ( workspace . isTrusted && bin ) {
38+ try {
39+ await fsPromises . access ( bin ) ;
40+ return bin ;
41+ } catch ( e ) {
42+ outputChannel . error ( `Invalid bin path: ${ bin } ` , e ) ;
43+ }
44+ }
45+ const ext = process . platform === 'win32' ? '.exe' : '' ;
46+ // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml
47+ return process . env . SERVER_PATH_DEV ?? join ( context . extensionPath , `./target/release/oxc_language_server${ ext } ` ) ;
48+ }
49+
3150 async activate (
3251 context : ExtensionContext ,
52+ binaryPath : string ,
3353 outputChannel : LogOutputChannel ,
3454 configService : ConfigService ,
3555 statusBarItemHandler : StatusBarItemHandler ,
@@ -63,30 +83,13 @@ export default class LinterTool implements ToolInterface {
6383
6484 context . subscriptions . push ( applyAllFixesFile ) ;
6585
66- async function findBinary ( ) : Promise < string > {
67- const bin = configService . getUserServerBinPath ( ) ;
68- if ( workspace . isTrusted && bin ) {
69- try {
70- await fsPromises . access ( bin ) ;
71- return bin ;
72- } catch ( e ) {
73- outputChannel . error ( `Invalid bin path: ${ bin } ` , e ) ;
74- }
75- }
76- const ext = process . platform === 'win32' ? '.exe' : '' ;
77- // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml
78- return process . env . SERVER_PATH_DEV ?? join ( context . extensionPath , `./target/release/oxc_language_server${ ext } ` ) ;
79- }
80-
81- const path = await findBinary ( ) ;
82-
83- const run : Executable = runExecutable ( path , configService . vsCodeConfig . nodePath ) ;
86+ const run : Executable = runExecutable ( binaryPath , configService . vsCodeConfig . nodePath ) ;
8487 const serverOptions : ServerOptions = {
8588 run,
8689 debug : run ,
8790 } ;
8891
89- outputChannel . info ( `Using server binary at: ${ path } ` ) ;
92+ outputChannel . info ( `Using server binary at: ${ binaryPath } ` ) ;
9093
9194 // see https://github.com/oxc-project/oxc/blob/9b475ad05b750f99762d63094174be6f6fc3c0eb/crates/oxc_linter/src/loader/partial_loader/mod.rs#L17-L20
9295 const supportedExtensions = [ 'astro' , 'cjs' , 'cts' , 'js' , 'jsx' , 'mjs' , 'mts' , 'svelte' , 'ts' , 'tsx' , 'vue' ] ;
0 commit comments