aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/ctx.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/ctx.ts
parentfcf15cc05afaeda6880664777ff2a3db342ea088 (diff)
parentd24e612106867c4bb6a1e59bf99aabfb7bc27823 (diff)
Merge pull request #3190 from matklad/reload
Simplify TS reload logic
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts18
1 files changed, 4 insertions, 14 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index ff6245f78..c06d8ac31 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,15 @@ 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 20
21 constructor(extCtx: vscode.ExtensionContext) { 21 constructor(extCtx: vscode.ExtensionContext) {
22 this.config = new Config(extCtx); 22 this.config = new Config(extCtx);
23 this.extCtx = extCtx; 23 this.extCtx = extCtx;
24 } 24 }
25 25
26 async restartServer() { 26 async startServer() {
27 const old = this.client; 27 assert(this.client == null);
28 if (old) { 28
29 await old.stop();
30 }
31 this.client = null;
32 const client = await createClient(this.config); 29 const client = await createClient(this.config);
33 if (!client) { 30 if (!client) {
34 throw new Error( 31 throw new Error(
@@ -41,9 +38,6 @@ export class Ctx {
41 await client.onReady(); 38 await client.onReady();
42 39
43 this.client = client; 40 this.client = client;
44 for (const hook of this.onDidRestartHooks) {
45 hook(client);
46 }
47 } 41 }
48 42
49 get activeRustEditor(): vscode.TextEditor | undefined { 43 get activeRustEditor(): vscode.TextEditor | undefined {
@@ -71,10 +65,6 @@ export class Ctx {
71 pushCleanup(d: Disposable) { 65 pushCleanup(d: Disposable) {
72 this.extCtx.subscriptions.push(d); 66 this.extCtx.subscriptions.push(d);
73 } 67 }
74
75 onDidRestart(hook: (client: lc.LanguageClient) => void) {
76 this.onDidRestartHooks.push(hook);
77 }
78} 68}
79 69
80export interface Disposable { 70export interface Disposable {