]> git.lizzy.rs Git - rust.git/blobdiff - editors/code/src/main.ts
Merge branch 'Veetaha-feat/sync-branch'
[rust.git] / editors / code / src / main.ts
index 16a94fceb1bc80f363aa23a97f1d6ca2782dbb1e..cdb63b46f92f04b7d493b005783d6d14a14316de 100644 (file)
@@ -41,7 +41,20 @@ export async function activate(context: vscode.ExtensionContext) {
 
     const config = new Config(context);
     const state = new PersistentState(context.globalState);
-    const serverPath = await bootstrap(config, state);
+    const serverPath = await bootstrap(config, state).catch(err => {
+        let message = "bootstrap error. ";
+
+        if (err.code === "EBUSY" || err.code === "ETXTBSY") {
+            message += "Other vscode windows might be using rust-analyzer, ";
+            message += "you should close them and reload this window to retry. ";
+        }
+
+        message += 'Open "Help > Toggle Developer Tools > Console" to see the logs ';
+        message += '(enable verbose logs with "rust-analyzer.trace.extension")';
+
+        log.error("Bootstrap error", err);
+        throw new Error(message);
+    });
 
     const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
     if (workspaceFolder === undefined) {
@@ -99,6 +112,7 @@ export async function activate(context: vscode.ExtensionContext) {
     ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand);
     ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction);
     ctx.registerCommand('applyActionGroup', commands.applyActionGroup);
+    ctx.registerCommand('gotoLocation', commands.gotoLocation);
 
     ctx.pushCleanup(activateTaskProvider(workspaceFolder));
 
@@ -165,7 +179,11 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
     assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
 
     const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
-    await download(artifact.browser_download_url, dest, "Downloading rust-analyzer extension");
+    await download({
+        url: artifact.browser_download_url,
+        dest,
+        progressTitle: "Downloading rust-analyzer extension",
+    });
 
     await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
     await fs.unlink(dest);
@@ -281,7 +299,17 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     const artifact = release.assets.find(artifact => artifact.name === binaryName);
     assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
 
-    await download(artifact.browser_download_url, dest, "Downloading rust-analyzer server", { mode: 0o755 });
+    // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
+    await fs.unlink(dest).catch(err => {
+        if (err.code !== "ENOENT") throw err;
+    });
+
+    await download({
+        url: artifact.browser_download_url,
+        dest,
+        progressTitle: "Downloading rust-analyzer server",
+        mode: 0o755
+    });
 
     // Patching executable if that's NixOS.
     if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {