Skip to content

Commit

Permalink
fix: activation failure without a workspace (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger authored Jan 27, 2024
1 parent 4ab1e11 commit 1e9163f
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -143,28 +143,33 @@ export async function activate(context: ExtensionContext) {
const reloadClient = async () => {
outputChannel.appendLine(`Biome binary found at ${server.command}`);

let destination: Uri | undefined = Uri.joinPath(
context.storageUri,
`./biome${process.platform === "win32" ? ".exe" : ""}`,
);
let destination: Uri | undefined;

// The context.storageURI is only defined when a workspace is opened.
if (context.storageUri) {
destination = Uri.joinPath(
context.storageUri,
`./biome${process.platform === "win32" ? ".exe" : ""}`,
);

if (server.workspaceDependency) {
try {
// Create the destination if it does not exist.
await workspace.fs.createDirectory(context.storageUri);

outputChannel.appendLine(
`Copying binary to temporary folder: ${destination}`,
);
await workspace.fs.copy(Uri.file(server.command), destination, {
overwrite: true,
});
} catch (error) {
outputChannel.appendLine(`Error copying file: ${error}`);
if (server.workspaceDependency) {
try {
// Create the destination if it does not exist.
await workspace.fs.createDirectory(context.storageUri);

outputChannel.appendLine(
`Copying binary to temporary folder: ${destination}`,
);
await workspace.fs.copy(Uri.file(server.command), destination, {
overwrite: true,
});
} catch (error) {
outputChannel.appendLine(`Error copying file: ${error}`);
destination = undefined;
}
} else {
destination = undefined;
}
} else {
destination = undefined;
}

outputChannel.appendLine(
@@ -381,7 +386,7 @@ async function getWorkspaceRelativePath(path: string) {
async function getWorkspaceDependency(
outputChannel: OutputChannel,
): Promise<string | undefined> {
for (const workspaceFolder of workspace.workspaceFolders) {
for (const workspaceFolder of workspace.workspaceFolders ?? []) {
// To resolve the @biomejs/cli-*, which is a transitive dependency of the
// @biomejs/biome package, we need to create a custom require function that
// is scoped to @biomejs/biome. This allows us to reliably resolve the
@@ -412,10 +417,6 @@ async function getWorkspaceDependency(
return undefined;
}

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;
}

0 comments on commit 1e9163f

Please sign in to comment.