Skip to content

Commit ee4e41c

Browse files
committed
Push IO and error handling up
1 parent 6167101 commit ee4e41c

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

editors/code/src/client.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ import * as lc from 'vscode-languageclient';
22
import * as vscode from 'vscode';
33

44
import { Config } from './config';
5-
import { ensureServerBinary } from './installation/server';
65
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
76

8-
export async function createClient(config: Config): Promise<null | lc.LanguageClient> {
7+
export async function createClient(config: Config, serverPath: string): Promise<lc.LanguageClient> {
98
// '.' Is the fallback if no folder is open
109
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
1110
// It might be a good idea to test if the uri points to a file.
1211
const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
1312

14-
const serverPath = await ensureServerBinary(config.serverSource);
15-
if (!serverPath) return null;
16-
1713
const run: lc.Executable = {
1814
command: serverPath,
1915
options: { cwd: workspaceFolderPath },

editors/code/src/ctx.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ export class Ctx {
2323
this.extCtx = extCtx;
2424
}
2525

26-
async startServer() {
26+
async startServer(serverPath: string) {
2727
assert(this.client == null);
2828

29-
const client = await createClient(this.config);
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-
}
29+
const client = await createClient(this.config, serverPath);
3630

3731
this.pushCleanup(client.start());
3832
await client.onReady();

editors/code/src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,27 @@ import { activateInlayHints } from './inlay_hints';
55
import { activateStatusDisplay } from './status_display';
66
import { Ctx } from './ctx';
77
import { activateHighlighting } from './highlighting';
8+
import { ensureServerBinary } from './installation/server';
89

910
let ctx: Ctx | undefined;
1011

1112
export async function activate(context: vscode.ExtensionContext) {
1213
ctx = new Ctx(context);
1314

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+
1423
// Note: we try to start the server before we activate type hints so that it
1524
// registers its `onDidChangeDocument` handler before us.
1625
//
1726
// This a horribly, horribly wrong way to deal with this problem.
1827
try {
19-
await ctx.startServer();
28+
await ctx.startServer(serverPath);
2029
} catch (e) {
2130
vscode.window.showErrorMessage(e.message);
2231
}

0 commit comments

Comments
 (0)