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/ctx.ts | |
parent | fcf15cc05afaeda6880664777ff2a3db342ea088 (diff) |
Simplify TS reload logic
Fixes #3164
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index ff6245f78..1eff88df2 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import { strict as assert } from "assert"; | ||
3 | 4 | ||
4 | import { Config } from './config'; | 5 | import { Config } from './config'; |
5 | import { createClient } from './client'; | 6 | import { createClient } from './client'; |
@@ -16,19 +17,16 @@ export class Ctx { | |||
16 | // on the event loop to get a better picture of what we can do here) | 17 | // on the event loop to get a better picture of what we can do here) |
17 | client: lc.LanguageClient | null = null; | 18 | client: lc.LanguageClient | null = null; |
18 | private extCtx: vscode.ExtensionContext; | 19 | private extCtx: vscode.ExtensionContext; |
19 | private onDidRestartHooks: Array<(client: lc.LanguageClient) => void> = []; | 20 | private onStartHooks: Array<(client: lc.LanguageClient) => void> = []; |
20 | 21 | ||
21 | constructor(extCtx: vscode.ExtensionContext) { | 22 | constructor(extCtx: vscode.ExtensionContext) { |
22 | this.config = new Config(extCtx); | 23 | this.config = new Config(extCtx); |
23 | this.extCtx = extCtx; | 24 | this.extCtx = extCtx; |
24 | } | 25 | } |
25 | 26 | ||
26 | async restartServer() { | 27 | async startServer() { |
27 | const old = this.client; | 28 | assert(this.client == null); |
28 | if (old) { | 29 | |
29 | await old.stop(); | ||
30 | } | ||
31 | this.client = null; | ||
32 | const client = await createClient(this.config); | 30 | const client = await createClient(this.config); |
33 | if (!client) { | 31 | if (!client) { |
34 | throw new Error( | 32 | throw new Error( |
@@ -41,7 +39,7 @@ export class Ctx { | |||
41 | await client.onReady(); | 39 | await client.onReady(); |
42 | 40 | ||
43 | this.client = client; | 41 | this.client = client; |
44 | for (const hook of this.onDidRestartHooks) { | 42 | for (const hook of this.onStartHooks) { |
45 | hook(client); | 43 | hook(client); |
46 | } | 44 | } |
47 | } | 45 | } |
@@ -72,8 +70,13 @@ export class Ctx { | |||
72 | this.extCtx.subscriptions.push(d); | 70 | this.extCtx.subscriptions.push(d); |
73 | } | 71 | } |
74 | 72 | ||
75 | onDidRestart(hook: (client: lc.LanguageClient) => void) { | 73 | onStart(hook: (client: lc.LanguageClient) => void) { |
76 | this.onDidRestartHooks.push(hook); | 74 | const client = this.client; |
75 | if (client == null) { | ||
76 | this.onStartHooks.push(hook); | ||
77 | } else { | ||
78 | hook(client) | ||
79 | } | ||
77 | } | 80 | } |
78 | } | 81 | } |
79 | 82 | ||