diff options
author | Aleksey Kladov <[email protected]> | 2020-02-17 13:03:33 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-17 13:03:33 +0000 |
commit | ee4e41cbea8ef3758ccebd9ffb35c5290aebfceb (patch) | |
tree | 7b377257a1f0e64611a31270b3dfd25d12acd96f | |
parent | 6167101302bcc2d7f1a345e0ee44e1411056b4b3 (diff) |
Push IO and error handling up
-rw-r--r-- | editors/code/src/client.ts | 6 | ||||
-rw-r--r-- | editors/code/src/ctx.ts | 10 | ||||
-rw-r--r-- | editors/code/src/main.ts | 11 |
3 files changed, 13 insertions, 14 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 11894973c..aaf2ef40e 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts | |||
@@ -2,18 +2,14 @@ import * as lc from 'vscode-languageclient'; | |||
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | 3 | ||
4 | import { Config } from './config'; | 4 | import { Config } from './config'; |
5 | import { ensureServerBinary } from './installation/server'; | ||
6 | import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; | 5 | import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; |
7 | 6 | ||
8 | export async function createClient(config: Config): Promise<null | lc.LanguageClient> { | 7 | export async function createClient(config: Config, serverPath: string): Promise<lc.LanguageClient> { |
9 | // '.' Is the fallback if no folder is open | 8 | // '.' Is the fallback if no folder is open |
10 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). | 9 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). |
11 | // It might be a good idea to test if the uri points to a file. | 10 | // It might be a good idea to test if the uri points to a file. |
12 | const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; | 11 | const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; |
13 | 12 | ||
14 | const serverPath = await ensureServerBinary(config.serverSource); | ||
15 | if (!serverPath) return null; | ||
16 | |||
17 | const run: lc.Executable = { | 13 | const run: lc.Executable = { |
18 | command: serverPath, | 14 | command: serverPath, |
19 | options: { cwd: workspaceFolderPath }, | 15 | options: { cwd: workspaceFolderPath }, |
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index c06d8ac31..935a6f2b5 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -23,16 +23,10 @@ export class Ctx { | |||
23 | this.extCtx = extCtx; | 23 | this.extCtx = extCtx; |
24 | } | 24 | } |
25 | 25 | ||
26 | async startServer() { | 26 | async startServer(serverPath: string) { |
27 | assert(this.client == null); | 27 | assert(this.client == null); |
28 | 28 | ||
29 | const client = await createClient(this.config); | 29 | const client = await createClient(this.config, serverPath); |
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 | 30 | ||
37 | this.pushCleanup(client.start()); | 31 | this.pushCleanup(client.start()); |
38 | await client.onReady(); | 32 | await client.onReady(); |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 0bf2c4829..ece4883bd 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -5,18 +5,27 @@ import { activateInlayHints } from './inlay_hints'; | |||
5 | import { activateStatusDisplay } from './status_display'; | 5 | 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 | 9 | ||
9 | let ctx: Ctx | undefined; | 10 | let ctx: Ctx | undefined; |
10 | 11 | ||
11 | export async function activate(context: vscode.ExtensionContext) { | 12 | export async function activate(context: vscode.ExtensionContext) { |
12 | ctx = new Ctx(context); | 13 | ctx = new Ctx(context); |
13 | 14 | ||
15 | const serverPath = await ensureServerBinary(ctx.config.serverSource); | ||
16 | if (serverPath == null) { | ||
17 | throw new Error( | ||
18 | "Rust Analyzer Language Server is not available. " + | ||
19 | "Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)." | ||
20 | ); | ||
21 | } | ||
22 | |||
14 | // Note: we try to start the server before we activate type hints so that it | 23 | // Note: we try to start the server before we activate type hints so that it |
15 | // registers its `onDidChangeDocument` handler before us. | 24 | // registers its `onDidChangeDocument` handler before us. |
16 | // | 25 | // |
17 | // This a horribly, horribly wrong way to deal with this problem. | 26 | // This a horribly, horribly wrong way to deal with this problem. |
18 | try { | 27 | try { |
19 | await ctx.startServer(); | 28 | await ctx.startServer(serverPath); |
20 | } catch (e) { | 29 | } catch (e) { |
21 | vscode.window.showErrorMessage(e.message); | 30 | vscode.window.showErrorMessage(e.message); |
22 | } | 31 | } |