aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/main.ts
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-17 12:54:33 +0000
committerGitHub <[email protected]>2020-02-17 12:54:33 +0000
commit6167101302bcc2d7f1a345e0ee44e1411056b4b3 (patch)
treedf40b6265f303b8fba5f804a7f7ff370e844dea0 /editors/code/src/main.ts
parentfcf15cc05afaeda6880664777ff2a3db342ea088 (diff)
parentd24e612106867c4bb6a1e59bf99aabfb7bc27823 (diff)
Merge pull request #3190 from matklad/reload
Simplify TS reload logic
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r--editors/code/src/main.ts38
1 files changed, 28 insertions, 10 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 5a99e96f0..0bf2c4829 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -11,7 +11,34 @@ let ctx: Ctx | undefined;
11export async function activate(context: vscode.ExtensionContext) { 11export async function activate(context: vscode.ExtensionContext) {
12 ctx = new Ctx(context); 12 ctx = new Ctx(context);
13 13
14 // Note: we try to start the server before we activate type hints so that it
15 // registers its `onDidChangeDocument` handler before us.
16 //
17 // This a horribly, horribly wrong way to deal with this problem.
18 try {
19 await ctx.startServer();
20 } catch (e) {
21 vscode.window.showErrorMessage(e.message);
22 }
23
14 // Commands which invokes manually via command palette, shortcut, etc. 24 // Commands which invokes manually via command palette, shortcut, etc.
25 ctx.registerCommand('reload', (ctx) => {
26 return async () => {
27 vscode.window.showInformationMessage('Reloading rust-analyzer...');
28 // @DanTup maneuver
29 // https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
30 await deactivate()
31 for (const sub of ctx.subscriptions) {
32 try {
33 sub.dispose();
34 } catch (e) {
35 console.error(e);
36 }
37 }
38 await activate(context)
39 }
40 })
41
15 ctx.registerCommand('analyzerStatus', commands.analyzerStatus); 42 ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
16 ctx.registerCommand('collectGarbage', commands.collectGarbage); 43 ctx.registerCommand('collectGarbage', commands.collectGarbage);
17 ctx.registerCommand('matchingBrace', commands.matchingBrace); 44 ctx.registerCommand('matchingBrace', commands.matchingBrace);
@@ -20,7 +47,6 @@ export async function activate(context: vscode.ExtensionContext) {
20 ctx.registerCommand('syntaxTree', commands.syntaxTree); 47 ctx.registerCommand('syntaxTree', commands.syntaxTree);
21 ctx.registerCommand('expandMacro', commands.expandMacro); 48 ctx.registerCommand('expandMacro', commands.expandMacro);
22 ctx.registerCommand('run', commands.run); 49 ctx.registerCommand('run', commands.run);
23 ctx.registerCommand('reload', commands.reload);
24 ctx.registerCommand('onEnter', commands.onEnter); 50 ctx.registerCommand('onEnter', commands.onEnter);
25 ctx.registerCommand('ssr', commands.ssr) 51 ctx.registerCommand('ssr', commands.ssr)
26 52
@@ -33,18 +59,10 @@ export async function activate(context: vscode.ExtensionContext) {
33 activateStatusDisplay(ctx); 59 activateStatusDisplay(ctx);
34 60
35 activateHighlighting(ctx); 61 activateHighlighting(ctx);
36 // Note: we try to start the server before we activate type hints so that it
37 // registers its `onDidChangeDocument` handler before us.
38 //
39 // This a horribly, horribly wrong way to deal with this problem.
40 try {
41 await ctx.restartServer();
42 } catch (e) {
43 vscode.window.showErrorMessage(e.message);
44 }
45 activateInlayHints(ctx); 62 activateInlayHints(ctx);
46} 63}
47 64
48export async function deactivate() { 65export async function deactivate() {
49 await ctx?.client?.stop(); 66 await ctx?.client?.stop();
67 ctx = undefined;
50} 68}