aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/client.ts15
-rw-r--r--editors/code/src/ctx.ts14
-rw-r--r--editors/code/src/main.ts4
3 files changed, 27 insertions, 6 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 131a2f19a..cb8beb343 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 | undefined, 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 | undefined, extraE
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 | undefined, extraE
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: {
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 9d8620823..dbfb9c6a1 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -7,6 +7,16 @@ import { createClient } from './client';
7import { isRustEditor, RustEditor } from './util'; 7import { isRustEditor, RustEditor } from './util';
8import { ServerStatusParams } from './lsp_ext'; 8import { ServerStatusParams } from './lsp_ext';
9 9
10export type Workspace =
11 {
12 kind: 'Workspace Folder',
13 folder: vscode.Uri,
14 }
15 | {
16 kind: 'Detached files',
17 files: vscode.TextDocument[],
18 };
19
10export class Ctx { 20export class Ctx {
11 private constructor( 21 private constructor(
12 readonly config: Config, 22 readonly config: Config,
@@ -22,9 +32,9 @@ export class Ctx {
22 config: Config, 32 config: Config,
23 extCtx: vscode.ExtensionContext, 33 extCtx: vscode.ExtensionContext,
24 serverPath: string, 34 serverPath: string,
25 cwd?: string, 35 workspace: Workspace,
26 ): Promise<Ctx> { 36 ): Promise<Ctx> {
27 const client = createClient(serverPath, cwd, config.serverExtraEnv); 37 const client = createClient(serverPath, workspace, config.serverExtraEnv);
28 38
29 const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); 39 const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
30 extCtx.subscriptions.push(statusBar); 40 extCtx.subscriptions.push(statusBar);
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index f0f47a75b..1a4af548d 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -49,7 +49,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
49 if (workspaceFolder === undefined) { 49 if (workspaceFolder === undefined) {
50 let rustDocuments = vscode.workspace.textDocuments.filter(document => isRustDocument(document)); 50 let rustDocuments = vscode.workspace.textDocuments.filter(document => isRustDocument(document));
51 if (rustDocuments.length > 0) { 51 if (rustDocuments.length > 0) {
52 ctx = await Ctx.create(config, context, serverPath); 52 ctx = await Ctx.create(config, context, serverPath, { kind: 'Detached files', files: rustDocuments });
53 } else { 53 } else {
54 throw new Error("no rust files are opened"); 54 throw new Error("no rust files are opened");
55 } 55 }
@@ -58,7 +58,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
58 // registers its `onDidChangeDocument` handler before us. 58 // registers its `onDidChangeDocument` handler before us.
59 // 59 //
60 // This a horribly, horribly wrong way to deal with this problem. 60 // This a horribly, horribly wrong way to deal with this problem.
61 ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath); 61 ctx = await Ctx.create(config, context, serverPath, { kind: "Workspace Folder", folder: workspaceFolder.uri });
62 ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config)); 62 ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
63 } 63 }
64 await initCommonContext(context, ctx); 64 await initCommonContext(context, ctx);