about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorKirill Bulatov <mail4score@gmail.com>2021-05-23 16:22:13 +0300
committerKirill Bulatov <mail4score@gmail.com>2021-05-23 22:46:20 +0300
commitb3383b06614e5f302a3afa2fc2c177303b5b6ca8 (patch)
treeecd109a689bdfd2885e1bd8ebcd181b2e98b4783 /editors/code
parentd9a5490646f68efdb70f84713d3a418a2b2a0b00 (diff)
downloadrust-b3383b06614e5f302a3afa2fc2c177303b5b6ca8.tar.gz
rust-b3383b06614e5f302a3afa2fc2c177303b5b6ca8.zip
Send detached files info to server via init params
Diffstat (limited to 'editors/code')
-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 131a2f19a77..cb8beb343ec 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -4,6 +4,7 @@ import * as ra from '../src/lsp_ext';
 import * as Is from 'vscode-languageclient/lib/common/utils/is';
 import { assert } from './util';
 import { WorkspaceEdit } from 'vscode';
+import { Workspace } from './ctx';
 
 export interface Env {
     [name: string]: string;
@@ -23,7 +24,7 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
     return result;
 }
 
-export function createClient(serverPath: string, cwd: string | undefined, extraEnv: Env): lc.LanguageClient {
+export function createClient(serverPath: string, workspace: Workspace, extraEnv: Env): lc.LanguageClient {
     // '.' Is the fallback if no folder is open
     // 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.
@@ -31,6 +32,11 @@ export function createClient(serverPath: string, cwd: string | undefined, extraE
     const newEnv = Object.assign({}, process.env);
     Object.assign(newEnv, extraEnv);
 
+    let cwd = undefined;
+    if (workspace.kind == "Workspace Folder") {
+        cwd = workspace.folder.fsPath;
+    };
+
     const run: lc.Executable = {
         command: serverPath,
         options: { cwd, env: newEnv },
@@ -43,9 +49,14 @@ export function createClient(serverPath: string, cwd: string | undefined, extraE
         'Rust Analyzer Language Server Trace',
     );
 
+    let initializationOptions = vscode.workspace.getConfiguration("rust-analyzer");
+    if (workspace.kind == "Detached files") {
+        initializationOptions = { "detachedFiles": workspace.files.map(file => file.uri.fsPath), ...initializationOptions };
+    }
+
     const clientOptions: lc.LanguageClientOptions = {
         documentSelector: [{ scheme: 'file', language: 'rust' }],
-        initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"),
+        initializationOptions,
         diagnosticCollectionName: "rustc",
         traceOutputChannel,
         middleware: {
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 9d8620823dd..dbfb9c6a1dd 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -7,6 +7,16 @@ import { createClient } from './client';
 import { isRustEditor, RustEditor } from './util';
 import { ServerStatusParams } from './lsp_ext';
 
+export type Workspace =
+    {
+        kind: 'Workspace Folder',
+        folder: vscode.Uri,
+    }
+    | {
+        kind: 'Detached files',
+        files: vscode.TextDocument[],
+    };
+
 export class Ctx {
     private constructor(
         readonly config: Config,
@@ -22,9 +32,9 @@ export class Ctx {
         config: Config,
         extCtx: vscode.ExtensionContext,
         serverPath: string,
-        cwd?: string,
+        workspace: Workspace,
     ): Promise<Ctx> {
-        const client = createClient(serverPath, cwd, config.serverExtraEnv);
+        const client = createClient(serverPath, workspace, config.serverExtraEnv);
 
         const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
         extCtx.subscriptions.push(statusBar);
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index f0f47a75b64..1a4af548d3a 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -49,7 +49,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
     if (workspaceFolder === undefined) {
         let rustDocuments = vscode.workspace.textDocuments.filter(document => isRustDocument(document));
         if (rustDocuments.length > 0) {
-            ctx = await Ctx.create(config, context, serverPath);
+            ctx = await Ctx.create(config, context, serverPath, { kind: 'Detached files', files: rustDocuments });
         } else {
             throw new Error("no rust files are opened");
         }
@@ -58,7 +58,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
         // registers its `onDidChangeDocument` handler before us.
         //
         // This a horribly, horribly wrong way to deal with this problem.
-        ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath);
+        ctx = await Ctx.create(config, context, serverPath, { kind: "Workspace Folder", folder: workspaceFolder.uri });
         ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
     }
     await initCommonContext(context, ctx);