Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vscode): server bin path resolution #227

Merged
merged 6 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one in #219.

Let me know if you'd rather I submit this in a separate PR.

"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
41 changes: 14 additions & 27 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 @@ -250,37 +252,22 @@ async function getWorkspaceDependency(
: `${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