aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-03-26 21:44:19 +0000
committerveetaha <[email protected]>2020-03-26 21:44:19 +0000
commite1a5e9565b9ef741f337251bef98ca70279f77eb (patch)
treeaa8cb3085290884bde856d00429bcf21556a2547
parent68ff71e3ab91f01039bb30121d05d0289bb1bd1f (diff)
vscode: fix memory leak on server restart
The memory leak was because on the server restrart the array of extensionContext.substiptions was not cleared
-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 814ae9dc2..6cde5c366 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -48,21 +48,19 @@ export async function activate(context: vscode.ExtensionContext) {
48 ctx = await Ctx.create(config, context, serverPath); 48 ctx = await Ctx.create(config, context, serverPath);
49 49
50 // Commands which invokes manually via command palette, shortcut, etc. 50 // Commands which invokes manually via command palette, shortcut, etc.
51 ctx.registerCommand('reload', (ctx) => { 51
52 return async () => { 52 // Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
53 vscode.window.showInformationMessage('Reloading rust-analyzer...'); 53 ctx.registerCommand('reload', _ => async () => {
54 // @DanTup maneuver 54 void vscode.window.showInformationMessage('Reloading rust-analyzer...');
55 // https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895 55 await deactivate();
56 await deactivate(); 56 while (context.subscriptions.length > 0) {
57 for (const sub of ctx.subscriptions) { 57 try {
58 try { 58 context.subscriptions.pop()!.dispose();
59 sub.dispose(); 59 } catch (err) {
60 } catch (e) { 60 log.error("Dispose error:", err);
61 log.error(e);
62 }
63 } 61 }
64 await activate(context); 62 }
65 }; 63 await activate(context).catch(log.error);
66 }); 64 });
67 65
68 ctx.registerCommand('analyzerStatus', commands.analyzerStatus); 66 ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
@@ -96,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) {
96} 94}
97 95
98export async function deactivate() { 96export async function deactivate() {
99 await ctx?.client?.stop(); 97 await ctx?.client.stop();
100 ctx = undefined; 98 ctx = undefined;
101} 99}
102 100