Skip to content

Commit

Permalink
feat(editors/vscode): update VSCode extention to use project's langua…
Browse files Browse the repository at this point in the history
…ge server (#6132)

closes #3426
  • Loading branch information
shulaoda authored Oct 6, 2024
1 parent 8729755 commit 1a5f293
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
Empty file removed editors/vscode/.prettierrc
Empty file.
45 changes: 41 additions & 4 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { promises as fsPromises } from 'node:fs';

import {
commands,
ConfigurationTarget,
Expand Down Expand Up @@ -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<string> {
const cfg = workspace.getConfiguration('oxc');

let bin = cfg.get<string>('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: {
Expand Down
4 changes: 2 additions & 2 deletions editors/vscode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["ES2020"],
"target": "es2021",
"lib": ["ES2021"],
"outDir": "dist",
"rootDir": "client",
"sourceMap": true,
Expand Down

0 comments on commit 1a5f293

Please sign in to comment.