about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2020-02-17 14:03:33 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2020-02-17 14:03:33 +0100
commitee4e41cbea8ef3758ccebd9ffb35c5290aebfceb (patch)
tree7b377257a1f0e64611a31270b3dfd25d12acd96f /editors/code
parent6167101302bcc2d7f1a345e0ee44e1411056b4b3 (diff)
downloadrust-ee4e41cbea8ef3758ccebd9ffb35c5290aebfceb.tar.gz
rust-ee4e41cbea8ef3758ccebd9ffb35c5290aebfceb.zip
Push IO and error handling up
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/client.ts6
-rw-r--r--editors/code/src/ctx.ts10
-rw-r--r--editors/code/src/main.ts11
3 files changed, 13 insertions, 14 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 11894973cd7..aaf2ef40e3e 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -2,18 +2,14 @@ import * as lc from 'vscode-languageclient';
 import * as vscode from 'vscode';
 
 import { Config } from './config';
-import { ensureServerBinary } from './installation/server';
 import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
 
-export async function createClient(config: Config): Promise<null | lc.LanguageClient> {
+export async function createClient(config: Config, serverPath: string): Promise<lc.LanguageClient> {
     // '.' Is the fallback if no folder is open
     // TODO?: Workspace folders support Uri's (eg: file://test.txt).
     // It might be a good idea to test if the uri points to a file.
     const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
 
-    const serverPath = await ensureServerBinary(config.serverSource);
-    if (!serverPath) return null;
-
     const run: lc.Executable = {
         command: serverPath,
         options: { cwd: workspaceFolderPath },
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index c06d8ac3176..935a6f2b5a3 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -23,16 +23,10 @@ export class Ctx {
         this.extCtx = extCtx;
     }
 
-    async startServer() {
+    async startServer(serverPath: string) {
         assert(this.client == null);
 
-        const client = await createClient(this.config);
-        if (!client) {
-            throw new Error(
-                "Rust Analyzer Language Server is not available. " +
-                "Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
-            );
-        }
+        const client = await createClient(this.config, serverPath);
 
         this.pushCleanup(client.start());
         await client.onReady();
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 0bf2c4829bb..ece4883bd69 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -5,18 +5,27 @@ import { activateInlayHints } from './inlay_hints';
 import { activateStatusDisplay } from './status_display';
 import { Ctx } from './ctx';
 import { activateHighlighting } from './highlighting';
+import { ensureServerBinary } from './installation/server';
 
 let ctx: Ctx | undefined;
 
 export async function activate(context: vscode.ExtensionContext) {
     ctx = new Ctx(context);
 
+    const serverPath = await ensureServerBinary(ctx.config.serverSource);
+    if (serverPath == null) {
+        throw new Error(
+            "Rust Analyzer Language Server is not available. " +
+            "Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
+        );
+    }
+
     // Note: we try to start the server before we activate type hints so that it
     // registers its `onDidChangeDocument` handler before us.
     //
     // This a horribly, horribly wrong way to deal with this problem.
     try {
-        await ctx.startServer();
+        await ctx.startServer(serverPath);
     } catch (e) {
         vscode.window.showErrorMessage(e.message);
     }