aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/ctx.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-17 13:24:07 +0000
committerGitHub <[email protected]>2020-02-17 13:24:07 +0000
commit4fea5808e9209c385e915d9d060c18520ce081b3 (patch)
treeb1b3be960ba393200c6676fa096f8c1e12e64cc2 /editors/code/src/ctx.ts
parent6167101302bcc2d7f1a345e0ee44e1411056b4b3 (diff)
parent3717b0e03f2336dcccea34c5a362b20966151b18 (diff)
Merge #3191
3191: Remove two stage constuction r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts39
1 files changed, 10 insertions, 29 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index c06d8ac31..dfc8aa7b9 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -1,43 +1,24 @@
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";
4 3
5import { Config } from './config'; 4import { Config } from './config';
6import { createClient } from './client'; 5import { createClient } from './client';
7 6
8export class Ctx { 7export class Ctx {
9 readonly config: Config; 8 private constructor(
10 // Because we have "reload server" action, various listeners **will** face a 9 readonly config: Config,
11 // situation where the client is not ready yet, and should be prepared to 10 private readonly extCtx: vscode.ExtensionContext,
12 // deal with it. 11 readonly client: lc.LanguageClient
13 // 12 ) {
14 // Ideally, this should be replaced with async getter though.
15 // FIXME: this actually needs syncronization of some kind (check how
16 // vscode deals with `deactivate()` call when extension has some work scheduled
17 // on the event loop to get a better picture of what we can do here)
18 client: lc.LanguageClient | null = null;
19 private extCtx: vscode.ExtensionContext;
20 13
21 constructor(extCtx: vscode.ExtensionContext) {
22 this.config = new Config(extCtx);
23 this.extCtx = extCtx;
24 } 14 }
25 15
26 async startServer() { 16 static async create(config: Config, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> {
27 assert(this.client == null); 17 const client = await createClient(config, serverPath);
28 18 const res = new Ctx(config, extCtx, client);
29 const client = await createClient(this.config); 19 res.pushCleanup(client.start());
30 if (!client) {
31 throw new Error(
32 "Rust Analyzer Language Server is not available. " +
33 "Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
34 );
35 }
36
37 this.pushCleanup(client.start());
38 await client.onReady(); 20 await client.onReady();
39 21 return res;
40 this.client = client;
41 } 22 }
42 23
43 get activeRustEditor(): vscode.TextEditor | undefined { 24 get activeRustEditor(): vscode.TextEditor | undefined {