mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
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>
This commit is contained in:
commit
d2619bf0ca
2 changed files with 21 additions and 23 deletions
|
@ -21,7 +21,7 @@ export class Config {
|
||||||
|
|
||||||
readonly package: {
|
readonly package: {
|
||||||
version: string;
|
version: string;
|
||||||
releaseTag: string | undefined;
|
releaseTag: string | null;
|
||||||
enableProposedApi: boolean | undefined;
|
enableProposedApi: boolean | undefined;
|
||||||
} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
|
} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
|
||||||
|
|
||||||
|
|
|
@ -48,21 +48,19 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
ctx = await Ctx.create(config, context, serverPath);
|
ctx = await Ctx.create(config, context, serverPath);
|
||||||
|
|
||||||
// Commands which invokes manually via command palette, shortcut, etc.
|
// Commands which invokes manually via command palette, shortcut, etc.
|
||||||
ctx.registerCommand('reload', (ctx) => {
|
|
||||||
return async () => {
|
// Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
|
||||||
vscode.window.showInformationMessage('Reloading rust-analyzer...');
|
ctx.registerCommand('reload', _ => async () => {
|
||||||
// @DanTup maneuver
|
void vscode.window.showInformationMessage('Reloading rust-analyzer...');
|
||||||
// https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
|
await deactivate();
|
||||||
await deactivate();
|
while (context.subscriptions.length > 0) {
|
||||||
for (const sub of ctx.subscriptions) {
|
try {
|
||||||
try {
|
context.subscriptions.pop()!.dispose();
|
||||||
sub.dispose();
|
} catch (err) {
|
||||||
} catch (e) {
|
log.error("Dispose error:", err);
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await activate(context);
|
}
|
||||||
};
|
await activate(context).catch(log.error);
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
|
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
|
||||||
|
@ -96,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deactivate() {
|
export async function deactivate() {
|
||||||
await ctx?.client?.stop();
|
await ctx?.client.stop();
|
||||||
ctx = undefined;
|
ctx = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,11 +108,13 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
|
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.channel === "stable") {
|
||||||
if (config.package.releaseTag === NIGHTLY_TAG) {
|
if (config.package.releaseTag === NIGHTLY_TAG) {
|
||||||
vscode.window.showWarningMessage(`You are running a nightly version of rust-analyzer extension.
|
void vscode.window.showWarningMessage(
|
||||||
To switch to stable, uninstall the extension and re-install it from the marketplace`);
|
`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;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -169,9 +169,7 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise<
|
||||||
log.debug("Checked binary availability via --version", res);
|
log.debug("Checked binary availability via --version", res);
|
||||||
log.debug(res, "--version output:", res.output);
|
log.debug(res, "--version output:", res.output);
|
||||||
if (res.status !== 0) {
|
if (res.status !== 0) {
|
||||||
throw new Error(
|
throw new Error(`Failed to execute ${path} --version`);
|
||||||
`Failed to execute ${path} --version`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
@ -185,7 +183,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
||||||
}
|
}
|
||||||
return explicitPath;
|
return explicitPath;
|
||||||
};
|
};
|
||||||
if (config.package.releaseTag === undefined) return "rust-analyzer";
|
if (config.package.releaseTag === null) return "rust-analyzer";
|
||||||
|
|
||||||
let binaryName: string | undefined = undefined;
|
let binaryName: string | undefined = undefined;
|
||||||
if (process.arch === "x64" || process.arch === "ia32") {
|
if (process.arch === "x64" || process.arch === "ia32") {
|
||||||
|
|
Loading…
Reference in a new issue