feat(editors/vscode): update VSCode extention to use project's language server (#6132)

closes #3426
This commit is contained in:
dalaoshu 2024-10-06 08:24:17 +08:00 committed by GitHub
parent 8729755baa
commit 1a5f293d9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 6 deletions

View file

@ -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<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: {

View file

@ -1,8 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["ES2020"],
"target": "es2021",
"lib": ["ES2021"],
"outDir": "dist",
"rootDir": "client",
"sourceMap": true,