|
| 1 | +import { promises as fsPromises } from 'node:fs'; |
| 2 | + |
1 | 3 | import { |
2 | 4 | commands, |
3 | 5 | ConfigurationTarget, |
@@ -90,10 +92,45 @@ export async function activate(context: ExtensionContext) { |
90 | 92 | const outputChannel = window.createOutputChannel(outputChannelName); |
91 | 93 | const traceOutputChannel = window.createOutputChannel(traceOutputChannelName); |
92 | 94 |
|
93 | | - const ext = process.platform === 'win32' ? '.exe' : ''; |
94 | | - // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml |
95 | | - const command = process.env.SERVER_PATH_DEV ?? |
96 | | - join(context.extensionPath, `./target/release/oxc_language_server${ext}`); |
| 95 | + async function findBinary(): Promise<string> { |
| 96 | + const cfg = workspace.getConfiguration('oxc'); |
| 97 | + |
| 98 | + let bin = cfg.get<string>('binPath', ''); |
| 99 | + if (bin) { |
| 100 | + try { |
| 101 | + await fsPromises.access(bin); |
| 102 | + return bin; |
| 103 | + } catch {} |
| 104 | + } |
| 105 | + |
| 106 | + const workspaceFolders = workspace.workspaceFolders; |
| 107 | + if (workspaceFolders) { |
| 108 | + try { |
| 109 | + return await Promise.any( |
| 110 | + workspaceFolders.map(async (folder) => { |
| 111 | + const binPath = join( |
| 112 | + folder.uri.fsPath, |
| 113 | + 'node_modules', |
| 114 | + '.bin', |
| 115 | + 'oxc_language_server', |
| 116 | + ); |
| 117 | + |
| 118 | + await fsPromises.access(binPath); |
| 119 | + return binPath; |
| 120 | + }), |
| 121 | + ); |
| 122 | + } catch {} |
| 123 | + } |
| 124 | + |
| 125 | + const ext = process.platform === 'win32' ? '.exe' : ''; |
| 126 | + // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml |
| 127 | + return ( |
| 128 | + process.env.SERVER_PATH_DEV ?? |
| 129 | + join(context.extensionPath, `./target/release/oxc_language_server${ext}`) |
| 130 | + ); |
| 131 | + } |
| 132 | + |
| 133 | + const command = await findBinary(); |
97 | 134 | const run: Executable = { |
98 | 135 | command: command!, |
99 | 136 | options: { |
|
0 commit comments