about summary refs log tree commit diff
path: root/editors
diff options
context:
space:
mode:
authorveetaha <veetaha2@gmail.com>2020-03-26 23:44:19 +0200
committerveetaha <veetaha2@gmail.com>2020-03-26 23:44:19 +0200
commite1a5e9565b9ef741f337251bef98ca70279f77eb (patch)
treeaa8cb3085290884bde856d00429bcf21556a2547 /editors
parent68ff71e3ab91f01039bb30121d05d0289bb1bd1f (diff)
downloadrust-e1a5e9565b9ef741f337251bef98ca70279f77eb.tar.gz
rust-e1a5e9565b9ef741f337251bef98ca70279f77eb.zip
vscode: fix memory leak on server restart
The memory leak was because on the server restrart the array of extensionContext.substiptions was not cleared
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/main.ts28
1 files changed, 13 insertions, 15 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 814ae9dc251..6cde5c36679 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;
 }