diff --git a/editors/vscode/.prettierrc b/editors/vscode/.prettierrc deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index d8a554a05131f..cd5210b91ac2d 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -1,3 +1,5 @@ +import { promises as fsPromises } from 'node:fs'; + import { commands, ConfigurationTarget, @@ -90,10 +92,45 @@ export async function activate(context: ExtensionContext) { const outputChannel = window.createOutputChannel(outputChannelName); const traceOutputChannel = window.createOutputChannel(traceOutputChannelName); - const ext = process.platform === 'win32' ? '.exe' : ''; - // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml - const command = process.env.SERVER_PATH_DEV ?? - join(context.extensionPath, `./target/release/oxc_language_server${ext}`); + async function findBinary(): Promise { + const cfg = workspace.getConfiguration('oxc'); + + let bin = cfg.get('binPath', ''); + if (bin) { + try { + await fsPromises.access(bin); + return bin; + } catch {} + } + + const workspaceFolders = workspace.workspaceFolders; + if (workspaceFolders) { + try { + return await Promise.any( + workspaceFolders.map(async (folder) => { + const binPath = join( + folder.uri.fsPath, + 'node_modules', + '.bin', + 'oxc_language_server', + ); + + await fsPromises.access(binPath); + return binPath; + }), + ); + } catch {} + } + + const ext = process.platform === 'win32' ? '.exe' : ''; + // NOTE: The `./target/release` path is aligned with the path defined in .github/workflows/release_vscode.yml + return ( + process.env.SERVER_PATH_DEV ?? + join(context.extensionPath, `./target/release/oxc_language_server${ext}`) + ); + } + + const command = await findBinary(); const run: Executable = { command: command!, options: { diff --git a/editors/vscode/tsconfig.json b/editors/vscode/tsconfig.json index 572c7b6757b05..098e7ba6ef597 100644 --- a/editors/vscode/tsconfig.json +++ b/editors/vscode/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "module": "commonjs", - "target": "es2020", - "lib": ["ES2020"], + "target": "es2021", + "lib": ["ES2021"], "outDir": "dist", "rootDir": "client", "sourceMap": true,