diff options
Diffstat (limited to 'editors/code/src/client.ts')
-rw-r--r-- | editors/code/src/client.ts | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 1ff64a930..2e3d4aba2 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts | |||
@@ -1,25 +1,21 @@ | |||
1 | import { homedir } from 'os'; | ||
2 | import * as lc from 'vscode-languageclient'; | 1 | import * as lc from 'vscode-languageclient'; |
3 | import { spawnSync } from 'child_process'; | ||
4 | 2 | ||
5 | import { window, workspace } from 'vscode'; | 3 | import { window, workspace } from 'vscode'; |
6 | import { Config } from './config'; | 4 | import { Config } from './config'; |
5 | import { ensureLanguageServerBinary } from './installation/language_server'; | ||
7 | 6 | ||
8 | export function createClient(config: Config): lc.LanguageClient { | 7 | export 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). It might be a good idea to test if the uri points to a file. | 9 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). |
11 | let folder: string = '.'; | 10 | // It might be a good idea to test if the uri points to a file. |
12 | if (workspace.workspaceFolders !== undefined) { | 11 | const workspaceFolderPath = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; |
13 | folder = workspace.workspaceFolders[0].uri.fsPath.toString(); | 12 | |
14 | } | 13 | const raLspServerPath = await ensureLanguageServerBinary(config.langServerSource); |
14 | if (!raLspServerPath) return null; | ||
15 | 15 | ||
16 | const command = expandPathResolving(config.raLspServerPath); | ||
17 | if (spawnSync(command, ["--version"]).status !== 0) { | ||
18 | window.showErrorMessage(`Unable to execute '${command} --version'`); | ||
19 | } | ||
20 | const run: lc.Executable = { | 16 | const run: lc.Executable = { |
21 | command, | 17 | command: raLspServerPath, |
22 | options: { cwd: folder }, | 18 | options: { cwd: workspaceFolderPath }, |
23 | }; | 19 | }; |
24 | const serverOptions: lc.ServerOptions = { | 20 | const serverOptions: lc.ServerOptions = { |
25 | run, | 21 | run, |
@@ -37,8 +33,7 @@ export function createClient(config: Config): lc.LanguageClient { | |||
37 | cargoWatchEnable: config.cargoWatchOptions.enable, | 33 | cargoWatchEnable: config.cargoWatchOptions.enable, |
38 | cargoWatchArgs: config.cargoWatchOptions.arguments, | 34 | cargoWatchArgs: config.cargoWatchOptions.arguments, |
39 | cargoWatchCommand: config.cargoWatchOptions.command, | 35 | cargoWatchCommand: config.cargoWatchOptions.command, |
40 | cargoWatchAllTargets: | 36 | cargoWatchAllTargets: config.cargoWatchOptions.allTargets, |
41 | config.cargoWatchOptions.allTargets, | ||
42 | excludeGlobs: config.excludeGlobs, | 37 | excludeGlobs: config.excludeGlobs, |
43 | useClientWatching: config.useClientWatching, | 38 | useClientWatching: config.useClientWatching, |
44 | featureFlags: config.featureFlags, | 39 | featureFlags: config.featureFlags, |
@@ -62,7 +57,7 @@ export function createClient(config: Config): lc.LanguageClient { | |||
62 | // This also requires considering our settings strategy, which is work which needs doing | 57 | // This also requires considering our settings strategy, which is work which needs doing |
63 | // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests | 58 | // @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests |
64 | res._tracer = { | 59 | res._tracer = { |
65 | log: (messageOrDataObject: string | any, data?: string) => { | 60 | log: (messageOrDataObject: string | unknown, data?: string) => { |
66 | if (typeof messageOrDataObject === 'string') { | 61 | if (typeof messageOrDataObject === 'string') { |
67 | if ( | 62 | if ( |
68 | messageOrDataObject.includes( | 63 | messageOrDataObject.includes( |
@@ -86,9 +81,3 @@ export function createClient(config: Config): lc.LanguageClient { | |||
86 | res.registerProposedFeatures(); | 81 | res.registerProposedFeatures(); |
87 | return res; | 82 | return res; |
88 | } | 83 | } |
89 | function expandPathResolving(path: string) { | ||
90 | if (path.startsWith('~/')) { | ||
91 | return path.replace('~', homedir()); | ||
92 | } | ||
93 | return path; | ||
94 | } | ||