about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-26 21:47:26 +0000
committerGitHub <noreply@github.com>2020-03-26 21:47:26 +0000
commitd2619bf0ca0c8c2ff8cda22beec9851887e4a4d5 (patch)
tree1956c9cc65b0dde6a1130e98a736bd3b1d1c8b2d /editors/code/src
parentb1594f108041813c9fa32538950c15c55202cbd5 (diff)
parent261ef1c4555839c2f054ead8dd622b20e1a39106 (diff)
downloadrust-d2619bf0ca0c8c2ff8cda22beec9851887e4a4d5.tar.gz
rust-d2619bf0ca0c8c2ff8cda22beec9851887e4a4d5.zip
Merge #3725
3725: vscode: fix local devel and remove disposables memory leak on server restrart r=matklad a=Veetaha



Co-authored-by: veetaha <veetaha2@gmail.com>
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/main.ts42
2 files changed, 21 insertions, 23 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 637aea27dae..e77462c1b00 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -21,7 +21,7 @@ export class Config {
 
     readonly package: {
         version: string;
-        releaseTag: string | undefined;
+        releaseTag: string | null;
         enableProposedApi: boolean | undefined;
     } = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
 
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index de27d95353b..980ed925b43 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -48,21 +48,19 @@ export async function activate(context: vscode.ExtensionContext) {
     ctx = await Ctx.create(config, context, serverPath);
 
     // Commands which invokes manually via command palette, shortcut, etc.
-    ctx.registerCommand('reload', (ctx) => {
-        return async () => {
-            vscode.window.showInformationMessage('Reloading rust-analyzer...');
-            // @DanTup maneuver
-            // https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
-            await deactivate();
-            for (const sub of ctx.subscriptions) {
-                try {
-                    sub.dispose();
-                } catch (e) {
-                    log.error(e);
-                }
+
+    // Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
+    ctx.registerCommand('reload', _ => async () => {
+        void vscode.window.showInformationMessage('Reloading rust-analyzer...');
+        await deactivate();
+        while (context.subscriptions.length > 0) {
+            try {
+                context.subscriptions.pop()!.dispose();
+            } catch (err) {
+                log.error("Dispose error:", err);
             }
-            await activate(context);
-        };
+        }
+        await activate(context).catch(log.error);
     });
 
     ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
@@ -96,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) {
 }
 
 export async function deactivate() {
-    await ctx?.client?.stop();
+    await ctx?.client.stop();
     ctx = undefined;
 }
 
@@ -110,11 +108,13 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
 }
 
 async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
-    if (config.package.releaseTag === undefined) return;
+    if (config.package.releaseTag === null) return;
     if (config.channel === "stable") {
         if (config.package.releaseTag === NIGHTLY_TAG) {
-            vscode.window.showWarningMessage(`You are running a nightly version of rust-analyzer extension.
-To switch to stable, uninstall the extension and re-install it from the marketplace`);
+            void vscode.window.showWarningMessage(
+                `You are running a nightly version of rust-analyzer extension. ` +
+                `To switch to stable, uninstall the extension and re-install it from the marketplace`
+            );
         }
         return;
     };
@@ -169,9 +169,7 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise<
     log.debug("Checked binary availability via --version", res);
     log.debug(res, "--version output:", res.output);
     if (res.status !== 0) {
-        throw new Error(
-            `Failed to execute ${path} --version`
-        );
+        throw new Error(`Failed to execute ${path} --version`);
     }
 
     return path;
@@ -185,7 +183,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
         }
         return explicitPath;
     };
-    if (config.package.releaseTag === undefined) return "rust-analyzer";
+    if (config.package.releaseTag === null) return "rust-analyzer";
 
     let binaryName: string | undefined = undefined;
     if (process.arch === "x64" || process.arch === "ia32") {