From dcdbbddd1630a4ed01906c2aff0e2b65ed99a591 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 12:17:01 +0100 Subject: Simplify TS reload logic Fixes #3164 --- editors/code/src/main.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'editors/code/src/main.ts') 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; export async function activate(context: vscode.ExtensionContext) { ctx = new Ctx(context); + ctx.registerCommand('reload', (ctx) => { + return async () => { + vscode.window.showInformationMessage('Reloading rust-analyzer...'); + // @DanTup maneuver + // https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895 + await deactivate() + for (const sub of ctx.subscriptions) { + try { + sub.dispose(); + } catch (e) { + console.error(e); + } + } + await activate(context) + } + }) + // Commands which invokes manually via command palette, shortcut, etc. ctx.registerCommand('analyzerStatus', commands.analyzerStatus); ctx.registerCommand('collectGarbage', commands.collectGarbage); @@ -20,7 +37,6 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('syntaxTree', commands.syntaxTree); ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('run', commands.run); - ctx.registerCommand('reload', commands.reload); ctx.registerCommand('onEnter', commands.onEnter); ctx.registerCommand('ssr', commands.ssr) @@ -38,7 +54,7 @@ export async function activate(context: vscode.ExtensionContext) { // // This a horribly, horribly wrong way to deal with this problem. try { - await ctx.restartServer(); + await ctx.startServer(); } catch (e) { vscode.window.showErrorMessage(e.message); } @@ -47,4 +63,5 @@ export async function activate(context: vscode.ExtensionContext) { export async function deactivate() { await ctx?.client?.stop(); + ctx = undefined; } -- cgit v1.2.3 From d24e612106867c4bb6a1e59bf99aabfb7bc27823 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 13:40:20 +0100 Subject: Simplify startup --- editors/code/src/main.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'editors/code/src/main.ts') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index ec488c340..0bf2c4829 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -11,6 +11,17 @@ let ctx: Ctx | undefined; export async function activate(context: vscode.ExtensionContext) { ctx = new Ctx(context); + // Note: we try to start the server before we activate type hints so that it + // registers its `onDidChangeDocument` handler before us. + // + // This a horribly, horribly wrong way to deal with this problem. + try { + await ctx.startServer(); + } catch (e) { + vscode.window.showErrorMessage(e.message); + } + + // Commands which invokes manually via command palette, shortcut, etc. ctx.registerCommand('reload', (ctx) => { return async () => { vscode.window.showInformationMessage('Reloading rust-analyzer...'); @@ -28,7 +39,6 @@ export async function activate(context: vscode.ExtensionContext) { } }) - // Commands which invokes manually via command palette, shortcut, etc. ctx.registerCommand('analyzerStatus', commands.analyzerStatus); ctx.registerCommand('collectGarbage', commands.collectGarbage); ctx.registerCommand('matchingBrace', commands.matchingBrace); @@ -49,15 +59,6 @@ export async function activate(context: vscode.ExtensionContext) { activateStatusDisplay(ctx); activateHighlighting(ctx); - // Note: we try to start the server before we activate type hints so that it - // registers its `onDidChangeDocument` handler before us. - // - // This a horribly, horribly wrong way to deal with this problem. - try { - await ctx.startServer(); - } catch (e) { - vscode.window.showErrorMessage(e.message); - } activateInlayHints(ctx); } -- cgit v1.2.3