diff options
author | Aleksey Kladov <[email protected]> | 2020-02-17 13:11:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-17 13:11:01 +0000 |
commit | 89afb1a841c83d41ca3da72217c377932cdf5e93 (patch) | |
tree | 21b54de0bec23693bb39e84a7dcf8be85312f291 /editors/code | |
parent | 978bea2b3110cf84defae37a56157b8b7016bd3d (diff) |
Remove two stage constuction
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/src/ctx.ts | 25 | ||||
-rw-r--r-- | editors/code/src/main.ts | 11 |
2 files changed, 15 insertions, 21 deletions
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 @@ | |||
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'; |
@@ -15,23 +14,21 @@ export class Ctx { | |||
15 | // FIXME: this actually needs syncronization of some kind (check how | 14 | // FIXME: this actually needs syncronization of some kind (check how |
16 | // vscode deals with `deactivate()` call when extension has some work scheduled | 15 | // 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) | 16 | // on the event loop to get a better picture of what we can do here) |
18 | client: lc.LanguageClient | null = null; | 17 | client: lc.LanguageClient; |
19 | private extCtx: vscode.ExtensionContext; | 18 | private extCtx: vscode.ExtensionContext; |
20 | 19 | ||
21 | constructor(extCtx: vscode.ExtensionContext) { | 20 | static async create(config: Config, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> { |
22 | this.config = new Config(extCtx); | 21 | const client = await createClient(config, serverPath); |
23 | this.extCtx = extCtx; | 22 | const res = new Ctx(config, extCtx, client); |
24 | } | 23 | res.pushCleanup(client.start()); |
25 | |||
26 | async startServer(serverPath: string) { | ||
27 | assert(this.client == null); | ||
28 | |||
29 | const client = await createClient(this.config, serverPath); | ||
30 | |||
31 | this.pushCleanup(client.start()); | ||
32 | await client.onReady(); | 24 | await client.onReady(); |
25 | return res; | ||
26 | } | ||
33 | 27 | ||
34 | this.client = client; | 28 | private constructor(config: Config, extCtx: vscode.ExtensionContext, client: lc.LanguageClient) { |
29 | this.config = config; | ||
30 | this.extCtx = extCtx; | ||
31 | this.client = client | ||
35 | } | 32 | } |
36 | 33 | ||
37 | get activeRustEditor(): vscode.TextEditor | undefined { | 34 | get activeRustEditor(): vscode.TextEditor | undefined { |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 947d5eb90..0ad7ef1bb 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -6,13 +6,14 @@ import { activateStatusDisplay } from './status_display'; | |||
6 | import { Ctx } from './ctx'; | 6 | import { Ctx } from './ctx'; |
7 | import { activateHighlighting } from './highlighting'; | 7 | import { activateHighlighting } from './highlighting'; |
8 | import { ensureServerBinary } from './installation/server'; | 8 | import { ensureServerBinary } from './installation/server'; |
9 | import { Config } from './config'; | ||
9 | 10 | ||
10 | let ctx: Ctx | undefined; | 11 | let ctx: Ctx | undefined; |
11 | 12 | ||
12 | export async function activate(context: vscode.ExtensionContext) { | 13 | export async function activate(context: vscode.ExtensionContext) { |
13 | ctx = new Ctx(context); | 14 | const config = new Config(context) |
14 | 15 | ||
15 | const serverPath = await ensureServerBinary(ctx.config.serverSource); | 16 | const serverPath = await ensureServerBinary(config.serverSource); |
16 | if (serverPath == null) { | 17 | if (serverPath == null) { |
17 | throw new Error( | 18 | throw new Error( |
18 | "Rust Analyzer Language Server is not available. " + | 19 | "Rust Analyzer Language Server is not available. " + |
@@ -24,11 +25,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
24 | // registers its `onDidChangeDocument` handler before us. | 25 | // registers its `onDidChangeDocument` handler before us. |
25 | // | 26 | // |
26 | // This a horribly, horribly wrong way to deal with this problem. | 27 | // This a horribly, horribly wrong way to deal with this problem. |
27 | try { | 28 | ctx = await Ctx.create(config, context, serverPath); |
28 | await ctx.startServer(serverPath); | ||
29 | } catch (e) { | ||
30 | vscode.window.showErrorMessage(e.message); | ||
31 | } | ||
32 | 29 | ||
33 | // Commands which invokes manually via command palette, shortcut, etc. | 30 | // Commands which invokes manually via command palette, shortcut, etc. |
34 | ctx.registerCommand('reload', (ctx) => { | 31 | ctx.registerCommand('reload', (ctx) => { |