diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-02-17 12:17:01 +0100 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-02-17 13:40:47 +0100 |
| commit | dcdbbddd1630a4ed01906c2aff0e2b65ed99a591 (patch) | |
| tree | e02793bf82f2956bf7c61dfbd7adfcfdf4df191b /editors/code/src/ctx.ts | |
| parent | fcf15cc05afaeda6880664777ff2a3db342ea088 (diff) | |
| download | rust-dcdbbddd1630a4ed01906c2aff0e2b65ed99a591.tar.gz rust-dcdbbddd1630a4ed01906c2aff0e2b65ed99a591.zip | |
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 ff6245f7899..1eff88df2a4 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; +import { strict as assert } from "assert"; import { Config } from './config'; import { createClient } from './client'; @@ -16,19 +17,16 @@ export class Ctx { // on the event loop to get a better picture of what we can do here) client: lc.LanguageClient | null = null; private extCtx: vscode.ExtensionContext; - private onDidRestartHooks: Array<(client: lc.LanguageClient) => void> = []; + private onStartHooks: Array<(client: lc.LanguageClient) => void> = []; constructor(extCtx: vscode.ExtensionContext) { this.config = new Config(extCtx); this.extCtx = extCtx; } - async restartServer() { - const old = this.client; - if (old) { - await old.stop(); - } - this.client = null; + async startServer() { + assert(this.client == null); + const client = await createClient(this.config); if (!client) { throw new Error( @@ -41,7 +39,7 @@ export class Ctx { await client.onReady(); this.client = client; - for (const hook of this.onDidRestartHooks) { + for (const hook of this.onStartHooks) { hook(client); } } @@ -72,8 +70,13 @@ export class Ctx { this.extCtx.subscriptions.push(d); } - onDidRestart(hook: (client: lc.LanguageClient) => void) { - this.onDidRestartHooks.push(hook); + onStart(hook: (client: lc.LanguageClient) => void) { + const client = this.client; + if (client == null) { + this.onStartHooks.push(hook); + } else { + hook(client) + } } } |
