From 89afb1a841c83d41ca3da72217c377932cdf5e93 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 14:11:01 +0100 Subject: Remove two stage constuction --- editors/code/src/ctx.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'editors/code/src/ctx.ts') diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 935a6f2b5..21f1025cf 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -1,6 +1,5 @@ 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'; @@ -15,23 +14,21 @@ export class Ctx { // FIXME: this actually needs syncronization of some kind (check how // vscode deals with `deactivate()` call when extension has some work scheduled // on the event loop to get a better picture of what we can do here) - client: lc.LanguageClient | null = null; + client: lc.LanguageClient; private extCtx: vscode.ExtensionContext; - constructor(extCtx: vscode.ExtensionContext) { - this.config = new Config(extCtx); - this.extCtx = extCtx; - } - - async startServer(serverPath: string) { - assert(this.client == null); - - const client = await createClient(this.config, serverPath); - - this.pushCleanup(client.start()); + static async create(config: Config, extCtx: vscode.ExtensionContext, serverPath: string): Promise { + const client = await createClient(config, serverPath); + const res = new Ctx(config, extCtx, client); + res.pushCleanup(client.start()); await client.onReady(); + return res; + } - this.client = client; + private constructor(config: Config, extCtx: vscode.ExtensionContext, client: lc.LanguageClient) { + this.config = config; + this.extCtx = extCtx; + this.client = client } get activeRustEditor(): vscode.TextEditor | undefined { -- cgit v1.2.3