From b3383b06614e5f302a3afa2fc2c177303b5b6ca8 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 23 May 2021 16:22:13 +0300 Subject: Send detached files info to server via init params --- editors/code/src/client.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'editors/code/src/client.ts') 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'; 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: { -- cgit v1.2.3