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.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 116f41df6..69dbe2535 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -4,6 +4,7 @@ import * as ra from '../src/lsp_ext';
4import * as Is from 'vscode-languageclient/lib/common/utils/is'; 4import * as Is from 'vscode-languageclient/lib/common/utils/is';
5import { assert } from './util'; 5import { assert } from './util';
6import { WorkspaceEdit } from 'vscode'; 6import { WorkspaceEdit } from 'vscode';
7import { Workspace } from './ctx';
7 8
8export interface Env { 9export interface Env {
9 [name: string]: string; 10 [name: string]: string;
@@ -23,7 +24,7 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
23 return result; 24 return result;
24} 25}
25 26
26export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc.LanguageClient { 27export function createClient(serverPath: string, workspace: Workspace, extraEnv: Env): lc.LanguageClient {
27 // '.' Is the fallback if no folder is open 28 // '.' Is the fallback if no folder is open
28 // TODO?: Workspace folders support Uri's (eg: file://test.txt). 29 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
29 // It might be a good idea to test if the uri points to a file. 30 // It might be a good idea to test if the uri points to a file.
@@ -31,6 +32,11 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
31 const newEnv = Object.assign({}, process.env); 32 const newEnv = Object.assign({}, process.env);
32 Object.assign(newEnv, extraEnv); 33 Object.assign(newEnv, extraEnv);
33 34
35 let cwd = undefined;
36 if (workspace.kind === "Workspace Folder") {
37 cwd = workspace.folder.fsPath;
38 };
39
34 const run: lc.Executable = { 40 const run: lc.Executable = {
35 command: serverPath, 41 command: serverPath,
36 options: { cwd, env: newEnv }, 42 options: { cwd, env: newEnv },
@@ -43,9 +49,14 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
43 'Rust Analyzer Language Server Trace', 49 'Rust Analyzer Language Server Trace',
44 ); 50 );
45 51
52 let initializationOptions = vscode.workspace.getConfiguration("rust-analyzer");
53 if (workspace.kind === "Detached Files") {
54 initializationOptions = { "detachedFiles": workspace.files.map(file => file.uri.fsPath), ...initializationOptions };
55 }
56
46 const clientOptions: lc.LanguageClientOptions = { 57 const clientOptions: lc.LanguageClientOptions = {
47 documentSelector: [{ scheme: 'file', language: 'rust' }], 58 documentSelector: [{ scheme: 'file', language: 'rust' }],
48 initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"), 59 initializationOptions,
49 diagnosticCollectionName: "rustc", 60 diagnosticCollectionName: "rustc",
50 traceOutputChannel, 61 traceOutputChannel,
51 middleware: { 62 middleware: {