diff options
author | Aleksey Kladov <[email protected]> | 2020-02-17 11:17:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-17 12:40:47 +0000 |
commit | dcdbbddd1630a4ed01906c2aff0e2b65ed99a591 (patch) | |
tree | e02793bf82f2956bf7c61dfbd7adfcfdf4df191b /editors/code/src/main.ts | |
parent | fcf15cc05afaeda6880664777ff2a3db342ea088 (diff) |
Simplify TS reload logic
Fixes #3164
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r-- | editors/code/src/main.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 5a99e96f0..ec488c340 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -11,6 +11,23 @@ let ctx: Ctx | undefined; | |||
11 | export async function activate(context: vscode.ExtensionContext) { | 11 | export async function activate(context: vscode.ExtensionContext) { |
12 | ctx = new Ctx(context); | 12 | ctx = new Ctx(context); |
13 | 13 | ||
14 | ctx.registerCommand('reload', (ctx) => { | ||
15 | return async () => { | ||
16 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | ||
17 | // @DanTup maneuver | ||
18 | // https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895 | ||
19 | await deactivate() | ||
20 | for (const sub of ctx.subscriptions) { | ||
21 | try { | ||
22 | sub.dispose(); | ||
23 | } catch (e) { | ||
24 | console.error(e); | ||
25 | } | ||
26 | } | ||
27 | await activate(context) | ||
28 | } | ||
29 | }) | ||
30 | |||
14 | // Commands which invokes manually via command palette, shortcut, etc. | 31 | // Commands which invokes manually via command palette, shortcut, etc. |
15 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); | 32 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); |
16 | ctx.registerCommand('collectGarbage', commands.collectGarbage); | 33 | ctx.registerCommand('collectGarbage', commands.collectGarbage); |
@@ -20,7 +37,6 @@ export async function activate(context: vscode.ExtensionContext) { | |||
20 | ctx.registerCommand('syntaxTree', commands.syntaxTree); | 37 | ctx.registerCommand('syntaxTree', commands.syntaxTree); |
21 | ctx.registerCommand('expandMacro', commands.expandMacro); | 38 | ctx.registerCommand('expandMacro', commands.expandMacro); |
22 | ctx.registerCommand('run', commands.run); | 39 | ctx.registerCommand('run', commands.run); |
23 | ctx.registerCommand('reload', commands.reload); | ||
24 | ctx.registerCommand('onEnter', commands.onEnter); | 40 | ctx.registerCommand('onEnter', commands.onEnter); |
25 | ctx.registerCommand('ssr', commands.ssr) | 41 | ctx.registerCommand('ssr', commands.ssr) |
26 | 42 | ||
@@ -38,7 +54,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
38 | // | 54 | // |
39 | // This a horribly, horribly wrong way to deal with this problem. | 55 | // This a horribly, horribly wrong way to deal with this problem. |
40 | try { | 56 | try { |
41 | await ctx.restartServer(); | 57 | await ctx.startServer(); |
42 | } catch (e) { | 58 | } catch (e) { |
43 | vscode.window.showErrorMessage(e.message); | 59 | vscode.window.showErrorMessage(e.message); |
44 | } | 60 | } |
@@ -47,4 +63,5 @@ export async function activate(context: vscode.ExtensionContext) { | |||
47 | 63 | ||
48 | export async function deactivate() { | 64 | export async function deactivate() { |
49 | await ctx?.client?.stop(); | 65 | await ctx?.client?.stop(); |
66 | ctx = undefined; | ||
50 | } | 67 | } |