Skip to content

Commit

Permalink
fix(vscode): server bin path resolution (#227)
Browse files Browse the repository at this point in the history
Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
nhedger and ematipico authored Sep 14, 2023
1 parent 6069a3c commit 84770ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
2 changes: 1 addition & 1 deletion editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 15 additions & 35 deletions editors/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -241,46 +243,23 @@ async function getWorkspaceRelativePath(path: string) {
async function getWorkspaceDependency(
outputChannel: OutputChannel,
): Promise<string | undefined> {
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;
}

Expand Down Expand Up @@ -376,6 +355,7 @@ async function getSocket(
): Promise<string> {
const process = spawn(command, ["__print_socket"], {
stdio: [null, "pipe", "pipe"],
shell: true,
});

const stdout = { content: "" };
Expand Down

0 comments on commit 84770ca

Please sign in to comment.