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 all 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
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,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is required to spawn the biome binary in node_modules/.bin under windows.

});

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