mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
vscode: fix memory leak on server restart
The memory leak was because on the server restrart the array of extensionContext.substiptions was not cleared
This commit is contained in:
parent
68ff71e3ab
commit
e1a5e9565b
1 changed files with 13 additions and 15 deletions
|
@ -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
|
||||
|
||||
// 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();
|
||||
for (const sub of ctx.subscriptions) {
|
||||
while (context.subscriptions.length > 0) {
|
||||
try {
|
||||
sub.dispose();
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue