Skip to content

Commit 1a5f293

Browse files
authored
feat(editors/vscode): update VSCode extention to use project's language server (#6132)
closes #3426
1 parent 8729755 commit 1a5f293

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

editors/vscode/.prettierrc

Whitespace-only changes.

editors/vscode/client/extension.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { promises as fsPromises } from 'node:fs';
2+
13
import {
24
commands,
35
ConfigurationTarget,
@@ -90,10 +92,45 @@ export async function activate(context: ExtensionContext) {
9092
const outputChannel = window.createOutputChannel(outputChannelName);
9193
const traceOutputChannel = window.createOutputChannel(traceOutputChannelName);
9294

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();
97134
const run: Executable = {
98135
command: command!,
99136
options: {

editors/vscode/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"target": "es2020",
5-
"lib": ["ES2020"],
4+
"target": "es2021",
5+
"lib": ["ES2021"],
66
"outDir": "dist",
77
"rootDir": "client",
88
"sourceMap": true,

0 commit comments

Comments
 (0)