aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/main.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r--editors/code/src/main.ts39
1 files changed, 32 insertions, 7 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a92c676fa..5ceab8b44 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -5,7 +5,6 @@ import { promises as fs, PathLike } from "fs";
5 5
6import * as commands from './commands'; 6import * as commands from './commands';
7import { activateInlayHints } from './inlay_hints'; 7import { activateInlayHints } from './inlay_hints';
8import { activateStatusDisplay } from './status_display';
9import { Ctx } from './ctx'; 8import { Ctx } from './ctx';
10import { Config, NIGHTLY_TAG } from './config'; 9import { Config, NIGHTLY_TAG } from './config';
11import { log, assert, isValidExecutable } from './util'; 10import { log, assert, isValidExecutable } from './util';
@@ -42,7 +41,20 @@ export async function activate(context: vscode.ExtensionContext) {
42 41
43 const config = new Config(context); 42 const config = new Config(context);
44 const state = new PersistentState(context.globalState); 43 const state = new PersistentState(context.globalState);
45 const serverPath = await bootstrap(config, state); 44 const serverPath = await bootstrap(config, state).catch(err => {
45 let message = "bootstrap error. ";
46
47 if (err.code === "EBUSY" || err.code === "ETXTBSY") {
48 message += "Other vscode windows might be using rust-analyzer, ";
49 message += "you should close them and reload this window to retry. ";
50 }
51
52 message += 'Open "Help > Toggle Developer Tools > Console" to see the logs ';
53 message += '(enable verbose logs with "rust-analyzer.trace.extension")';
54
55 log.error("Bootstrap error", err);
56 throw new Error(message);
57 });
46 58
47 const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; 59 const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
48 if (workspaceFolder === undefined) { 60 if (workspaceFolder === undefined) {
@@ -100,10 +112,9 @@ export async function activate(context: vscode.ExtensionContext) {
100 ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand); 112 ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand);
101 ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction); 113 ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction);
102 ctx.registerCommand('applyActionGroup', commands.applyActionGroup); 114 ctx.registerCommand('applyActionGroup', commands.applyActionGroup);
115 ctx.registerCommand('gotoLocation', commands.gotoLocation);
103 116
104 ctx.pushCleanup(activateTaskProvider(workspaceFolder)); 117 ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
105
106 activateStatusDisplay(ctx);
107 118
108 activateInlayHints(ctx); 119 activateInlayHints(ctx);
109 120
@@ -168,7 +179,11 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
168 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 179 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
169 180
170 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); 181 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
171 await download(artifact.browser_download_url, dest, "Downloading rust-analyzer extension"); 182 await download({
183 url: artifact.browser_download_url,
184 dest,
185 progressTitle: "Downloading rust-analyzer extension",
186 });
172 187
173 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); 188 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
174 await fs.unlink(dest); 189 await fs.unlink(dest);
@@ -284,7 +299,17 @@ async function getServer(config: Config, state: PersistentState): Promise<string
284 const artifact = release.assets.find(artifact => artifact.name === binaryName); 299 const artifact = release.assets.find(artifact => artifact.name === binaryName);
285 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 300 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
286 301
287 await download(artifact.browser_download_url, dest, "Downloading rust-analyzer server", { mode: 0o755 }); 302 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
303 await fs.unlink(dest).catch(err => {
304 if (err.code !== "ENOENT") throw err;
305 });
306
307 await download({
308 url: artifact.browser_download_url,
309 dest,
310 progressTitle: "Downloading rust-analyzer server",
311 mode: 0o755
312 });
288 313
289 // Patching executable if that's NixOS. 314 // Patching executable if that's NixOS.
290 if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) { 315 if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {