aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/client.ts')
-rw-r--r--editors/code/src/client.ts22
1 files changed, 5 insertions, 17 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 7e7e909dd..7639ed44b 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -1,24 +1,18 @@
1import { homedir } from 'os';
2import * as lc from 'vscode-languageclient'; 1import * as lc from 'vscode-languageclient';
3import { spawnSync } from 'child_process';
4 2
5import { window, workspace } from 'vscode'; 3import { window, workspace } from 'vscode';
6import { Config } from './config'; 4import { Config } from './config';
5import { ensureLanguageServerBinary } from './installation/language_server';
7 6
8export function createClient(config: Config): lc.LanguageClient { 7export async function createClient(config: Config): Promise<null | 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 = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; 11 const workspaceFolderPath = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
13 12
14 const raLspServerPath = expandPathResolving(config.raLspServerPath); 13 const raLspServerPath = await ensureLanguageServerBinary(config.raLspServerSource);
15 if (spawnSync(raLspServerPath, ["--version"]).status !== 0) { 14 if (!raLspServerPath) return null;
16 window.showErrorMessage( 15
17 `Unable to execute '${raLspServerPath} --version'\n\n` +
18 `Perhaps it is not in $PATH?\n\n` +
19 `PATH=${process.env.PATH}\n`
20 );
21 }
22 const run: lc.Executable = { 16 const run: lc.Executable = {
23 command: raLspServerPath, 17 command: raLspServerPath,
24 options: { cwd: workspaceFolderPath }, 18 options: { cwd: workspaceFolderPath },
@@ -87,9 +81,3 @@ export function createClient(config: Config): lc.LanguageClient {
87 res.registerProposedFeatures(); 81 res.registerProposedFeatures();
88 return res; 82 return res;
89} 83}
90function expandPathResolving(path: string) {
91 if (path.startsWith('~/')) {
92 return path.replace('~', homedir());
93 }
94 return path;
95}