Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: follow the suggestions
  • Loading branch information
shulaoda committed Sep 28, 2024
commit dd9b84726549e8f34b96ecca012c3f26489fe255
3 changes: 0 additions & 3 deletions editors/vscode/.prettierrc

This file was deleted.

30 changes: 22 additions & 8 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'node:fs';
import { promises as fsPromises } from 'node:fs';

import {
commands,
Expand Down Expand Up @@ -92,27 +92,41 @@ export async function activate(context: ExtensionContext) {
const outputChannel = window.createOutputChannel(outputChannelName);
const traceOutputChannel = window.createOutputChannel(traceOutputChannelName);

function findBinary(): string {
async function findBinary(): Promise<string> {
const cfg = workspace.getConfiguration('oxc');

let bin = cfg.get<string>('binPath', '');
if (bin && existsSync(bin)) {
return bin;
if (bin) {
try {
await fsPromises.access(bin);
return bin;
} catch {}
}

const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders) {
for (const folder of workspaceFolders) {
const checks = workspaceFolders.map(async (folder) => {
const binPath = join(
folder.uri.fsPath,
'node_modules',
'.bin',
'oxc_language_server',
);
if (existsSync(binPath)) {

try {
await fsPromises.access(binPath);
return binPath;
} catch {
return undefined;
}
}
});

// Wait for all checks and return the first valid path
const result = (await Promise.all(checks)).find(
(path) => path !== undefined,
);

if (result) return result;
}

const ext = process.platform === 'win32' ? '.exe' : '';
Expand All @@ -123,7 +137,7 @@ export async function activate(context: ExtensionContext) {
);
}

const command = findBinary();
const command = await findBinary();
const run: Executable = {
command: command!,
options: {
Expand Down