Skip to content

Commit d2619bf

Browse files
bors[bot]Veetaha
andauthored
Merge #3725
3725: vscode: fix local devel and remove disposables memory leak on server restrart r=matklad a=Veetaha Co-authored-by: veetaha <[email protected]>
2 parents b1594f1 + 261ef1c commit d2619bf

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

editors/code/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Config {
2121

2222
readonly package: {
2323
version: string;
24-
releaseTag: string | undefined;
24+
releaseTag: string | null;
2525
enableProposedApi: boolean | undefined;
2626
} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
2727

editors/code/src/main.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,19 @@ export async function activate(context: vscode.ExtensionContext) {
4848
ctx = await Ctx.create(config, context, serverPath);
4949

5050
// Commands which invokes manually via command palette, shortcut, etc.
51-
ctx.registerCommand('reload', (ctx) => {
52-
return async () => {
53-
vscode.window.showInformationMessage('Reloading rust-analyzer...');
54-
// @DanTup maneuver
55-
// https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
56-
await deactivate();
57-
for (const sub of ctx.subscriptions) {
58-
try {
59-
sub.dispose();
60-
} catch (e) {
61-
log.error(e);
62-
}
51+
52+
// Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
53+
ctx.registerCommand('reload', _ => async () => {
54+
void vscode.window.showInformationMessage('Reloading rust-analyzer...');
55+
await deactivate();
56+
while (context.subscriptions.length > 0) {
57+
try {
58+
context.subscriptions.pop()!.dispose();
59+
} catch (err) {
60+
log.error("Dispose error:", err);
6361
}
64-
await activate(context);
65-
};
62+
}
63+
await activate(context).catch(log.error);
6664
});
6765

6866
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
@@ -96,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) {
9694
}
9795

9896
export async function deactivate() {
99-
await ctx?.client?.stop();
97+
await ctx?.client.stop();
10098
ctx = undefined;
10199
}
102100

@@ -110,11 +108,13 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
110108
}
111109

112110
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
113-
if (config.package.releaseTag === undefined) return;
111+
if (config.package.releaseTag === null) return;
114112
if (config.channel === "stable") {
115113
if (config.package.releaseTag === NIGHTLY_TAG) {
116-
vscode.window.showWarningMessage(`You are running a nightly version of rust-analyzer extension.
117-
To switch to stable, uninstall the extension and re-install it from the marketplace`);
114+
void vscode.window.showWarningMessage(
115+
`You are running a nightly version of rust-analyzer extension. ` +
116+
`To switch to stable, uninstall the extension and re-install it from the marketplace`
117+
);
118118
}
119119
return;
120120
};
@@ -169,9 +169,7 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise<
169169
log.debug("Checked binary availability via --version", res);
170170
log.debug(res, "--version output:", res.output);
171171
if (res.status !== 0) {
172-
throw new Error(
173-
`Failed to execute ${path} --version`
174-
);
172+
throw new Error(`Failed to execute ${path} --version`);
175173
}
176174

177175
return path;
@@ -185,7 +183,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
185183
}
186184
return explicitPath;
187185
};
188-
if (config.package.releaseTag === undefined) return "rust-analyzer";
186+
if (config.package.releaseTag === null) return "rust-analyzer";
189187

190188
let binaryName: string | undefined = undefined;
191189
if (process.arch === "x64" || process.arch === "ia32") {

0 commit comments

Comments
 (0)