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/ctx.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'editors/code/src/ctx.ts') 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 @@ 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) + } } } -- cgit v1.2.3