diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-26 21:47:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-26 21:47:26 +0000 |
commit | d2619bf0ca0c8c2ff8cda22beec9851887e4a4d5 (patch) | |
tree | 1956c9cc65b0dde6a1130e98a736bd3b1d1c8b2d | |
parent | b1594f108041813c9fa32538950c15c55202cbd5 (diff) | |
parent | 261ef1c4555839c2f054ead8dd622b20e1a39106 (diff) |
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]>
-rw-r--r-- | editors/code/src/config.ts | 2 | ||||
-rw-r--r-- | editors/code/src/main.ts | 42 |
2 files changed, 21 insertions, 23 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 637aea27d..e77462c1b 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -21,7 +21,7 @@ export class Config { | |||
21 | 21 | ||
22 | readonly package: { | 22 | readonly package: { |
23 | version: string; | 23 | version: string; |
24 | releaseTag: string | undefined; | 24 | releaseTag: string | null; |
25 | enableProposedApi: boolean | undefined; | 25 | enableProposedApi: boolean | undefined; |
26 | } = vscode.extensions.getExtension(this.extensionId)!.packageJSON; | 26 | } = vscode.extensions.getExtension(this.extensionId)!.packageJSON; |
27 | 27 | ||
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index de27d9535..980ed925b 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 | ||
98 | export async function deactivate() { | 96 | export async function deactivate() { |
99 | await ctx?.client?.stop(); | 97 | await ctx?.client.stop(); |
100 | ctx = undefined; | 98 | ctx = undefined; |
101 | } | 99 | } |
102 | 100 | ||
@@ -110,11 +108,13 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string | |||
110 | } | 108 | } |
111 | 109 | ||
112 | async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> { | 110 | async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> { |
113 | if (config.package.releaseTag === undefined) return; | 111 | if (config.package.releaseTag === null) return; |
114 | if (config.channel === "stable") { | 112 | if (config.channel === "stable") { |
115 | if (config.package.releaseTag === NIGHTLY_TAG) { | 113 | if (config.package.releaseTag === NIGHTLY_TAG) { |
116 | vscode.window.showWarningMessage(`You are running a nightly version of rust-analyzer extension. | 114 | void vscode.window.showWarningMessage( |
117 | To switch to stable, uninstall the extension and re-install it from the marketplace`); | 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 | ); | ||
118 | } | 118 | } |
119 | return; | 119 | return; |
120 | }; | 120 | }; |
@@ -169,9 +169,7 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise< | |||
169 | log.debug("Checked binary availability via --version", res); | 169 | log.debug("Checked binary availability via --version", res); |
170 | log.debug(res, "--version output:", res.output); | 170 | log.debug(res, "--version output:", res.output); |
171 | if (res.status !== 0) { | 171 | if (res.status !== 0) { |
172 | throw new Error( | 172 | throw new Error(`Failed to execute ${path} --version`); |
173 | `Failed to execute ${path} --version` | ||
174 | ); | ||
175 | } | 173 | } |
176 | 174 | ||
177 | return path; | 175 | return path; |
@@ -185,7 +183,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
185 | } | 183 | } |
186 | return explicitPath; | 184 | return explicitPath; |
187 | }; | 185 | }; |
188 | if (config.package.releaseTag === undefined) return "rust-analyzer"; | 186 | if (config.package.releaseTag === null) return "rust-analyzer"; |
189 | 187 | ||
190 | let binaryName: string | undefined = undefined; | 188 | let binaryName: string | undefined = undefined; |
191 | if (process.arch === "x64" || process.arch === "ia32") { | 189 | if (process.arch === "x64" || process.arch === "ia32") { |