aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/ctx.ts
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-17 11:17:01 +0000
committerAleksey Kladov <[email protected]>2020-02-17 12:40:47 +0000
commitdcdbbddd1630a4ed01906c2aff0e2b65ed99a591 (patch)
treee02793bf82f2956bf7c61dfbd7adfcfdf4df191b /editors/code/src/ctx.ts
parentfcf15cc05afaeda6880664777ff2a3db342ea088 (diff)
Simplify TS reload logic
Fixes #3164
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts23
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 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import { strict as assert } from "assert";
3 4
4import { Config } from './config'; 5import { Config } from './config';
5import { createClient } from './client'; 6import { 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