diff options
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 39 |
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 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import { strict as assert } from "assert"; | ||
4 | 3 | ||
5 | import { Config } from './config'; | 4 | import { Config } from './config'; |
6 | import { createClient } from './client'; | 5 | import { createClient } from './client'; |
7 | 6 | ||
8 | export class Ctx { | 7 | export 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 { |