From 84770ca0b284356fad18370659fec0fc54d086a3 Mon Sep 17 00:00:00 2001 From: Nicolas Hedger <649677+nhedger@users.noreply.github.com> Date: Thu, 14 Sep 2023 18:08:47 +0200 Subject: [PATCH] fix(vscode): server bin path resolution (#227) Co-authored-by: Emanuele Stoppa --- editors/vscode/package.json | 2 +- editors/vscode/src/main.ts | 50 +++++++++++-------------------------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 82ef268ffc0e..16880ddede98 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -135,7 +135,7 @@ "license": "MIT", "scripts": { "compile": "esbuild src/main.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --target=node14", - "watch": "pnpm run compile -- --sourcemap --watch", + "watch": "pnpm run compile --sourcemap --watch", "package": "vsce package --no-dependencies -o biome_lsp.vsix", "build": "pnpm run compile --minify && pnpm run package", "install-extension": "code --install-extension biome_lsp.vsix --force", diff --git a/editors/vscode/src/main.ts b/editors/vscode/src/main.ts index da0c57e4a586..5623c0530c88 100644 --- a/editors/vscode/src/main.ts +++ b/editors/vscode/src/main.ts @@ -71,6 +71,8 @@ export async function activate(context: ExtensionContext) { return; } + outputChannel.appendLine(`Using Biome from ${command}`); + const statusBar = new StatusBar(); const serverOptions: ServerOptions = createMessageTransports.bind( @@ -241,46 +243,23 @@ async function getWorkspaceRelativePath(path: string) { async function getWorkspaceDependency( outputChannel: OutputChannel, ): Promise { - const packageName = PLATFORMS[process.platform]?.[process.arch]?.package; - - const manifestName = `${packageName}/package.json`; - const binaryName = - process.platform === "win32" - ? `${packageName}/biome.exe` - : `${packageName}/biome`; - for (const workspaceFolder of workspace.workspaceFolders) { - try { - const options = { - basedir: workspaceFolder.uri.fsPath, - }; - - const [manifestPath, binaryPath] = await Promise.all([ - resolveAsync(manifestName, options), - resolveAsync(binaryName, options), - ]); - - if (!(manifestPath && binaryPath)) { - continue; - } - - // Load the package.json manifest of the resolved package - const manifestUri = Uri.file(manifestPath); - const manifestData = await workspace.fs.readFile(manifestUri); - - const { version } = JSON.parse(new TextDecoder().decode(manifestData)); - if (typeof version !== "string") { - continue; - } + const path = Uri.joinPath( + workspaceFolder.uri, + "node_modules", + ".bin", + "biome", + ); - return binaryPath; - } catch (e) { - console.log(e); - window.showWarningMessage(`The extension couldn't resolve ${manifestName} or ${binaryName}. - If you installed "@biomejs/biome", it's a resolving issue due to your package manager. Check the troubleshooting section of the extension for more information on how to fix the issue.`); + if (await fileExists(path)) { + return path.fsPath; } } + window.showWarningMessage( + "Unable to resolve the biome server from your dependencies. Make sure it's correctly installed, or untick the `requireConfiguration` setting to use the bundled binary.", + ); + return undefined; } @@ -376,6 +355,7 @@ async function getSocket( ): Promise { const process = spawn(command, ["__print_socket"], { stdio: [null, "pipe", "pipe"], + shell: true, }); const stdout = { content: "" };