aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json8
-rw-r--r--editors/code/src/client.ts11
-rw-r--r--editors/code/src/commands.ts10
-rw-r--r--editors/code/src/config.ts3
-rw-r--r--editors/code/src/ctx.ts2
5 files changed, 29 insertions, 5 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 4bae5d647..3e55a3523 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -288,6 +288,14 @@
288 "default": null, 288 "default": null,
289 "markdownDescription": "Path to rust-analyzer executable (points to bundled binary by default). If this is set, then `#rust-analyzer.updates.channel#` setting is not used" 289 "markdownDescription": "Path to rust-analyzer executable (points to bundled binary by default). If this is set, then `#rust-analyzer.updates.channel#` setting is not used"
290 }, 290 },
291 "rust-analyzer.server.extraEnv": {
292 "type": [
293 "null",
294 "object"
295 ],
296 "default": null,
297 "markdownDescription": "Extra environment variables that will be passed to the rust-analyzer executable. Useful for passing e.g. `RA_LOG` for debugging."
298 },
291 "rust-analyzer.trace.server": { 299 "rust-analyzer.trace.server": {
292 "type": "string", 300 "type": "string",
293 "scope": "window", 301 "scope": "window",
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 63ab82dde..539e487ec 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -6,6 +6,10 @@ import { DocumentSemanticsTokensSignature, DocumentSemanticsTokensEditsSignature
6import { assert } from './util'; 6import { assert } from './util';
7import { WorkspaceEdit } from 'vscode'; 7import { WorkspaceEdit } from 'vscode';
8 8
9export interface Env {
10 [name: string]: string;
11}
12
9function renderCommand(cmd: ra.CommandLink) { 13function renderCommand(cmd: ra.CommandLink) {
10 return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`; 14 return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`;
11} 15}
@@ -27,14 +31,17 @@ async function semanticHighlightingWorkaround<R, F extends (...args: any[]) => v
27 return res; 31 return res;
28} 32}
29 33
30export function createClient(serverPath: string, cwd: string): lc.LanguageClient { 34export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc.LanguageClient {
31 // '.' Is the fallback if no folder is open 35 // '.' Is the fallback if no folder is open
32 // TODO?: Workspace folders support Uri's (eg: file://test.txt). 36 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
33 // It might be a good idea to test if the uri points to a file. 37 // It might be a good idea to test if the uri points to a file.
34 38
39 const newEnv = Object.assign({}, process.env);
40 Object.assign(newEnv, extraEnv);
41
35 const run: lc.Executable = { 42 const run: lc.Executable = {
36 command: serverPath, 43 command: serverPath,
37 options: { cwd }, 44 options: { cwd, env: newEnv },
38 }; 45 };
39 const serverOptions: lc.ServerOptions = { 46 const serverOptions: lc.ServerOptions = {
40 run, 47 run,
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 2911bccd5..c1c9f9754 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -524,8 +524,14 @@ export function resolveCodeAction(ctx: Ctx): Cmd {
524 if (!item.edit) { 524 if (!item.edit) {
525 return; 525 return;
526 } 526 }
527 const edit = client.protocol2CodeConverter.asWorkspaceEdit(item.edit); 527 const itemEdit = item.edit;
528 await vscode.workspace.applyEdit(edit); 528 const edit = client.protocol2CodeConverter.asWorkspaceEdit(itemEdit);
529 // filter out all text edits and recreate the WorkspaceEdit without them so we can apply
530 // snippet edits on our own
531 const itemEditWithoutTextEdits = { ...item, documentChanges: itemEdit.documentChanges?.filter(change => "kind" in change) };
532 const editWithoutTextEdits = client.protocol2CodeConverter.asWorkspaceEdit(itemEditWithoutTextEdits);
533 await applySnippetWorkspaceEdit(edit);
534 await vscode.workspace.applyEdit(editWithoutTextEdits);
529 }; 535 };
530} 536}
531 537
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 848e92af9..fe9f3b4a8 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -1,4 +1,5 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import { Env } from './client';
2import { log } from "./util"; 3import { log } from "./util";
3 4
4export type UpdatesChannel = "stable" | "nightly"; 5export type UpdatesChannel = "stable" | "nightly";
@@ -13,6 +14,7 @@ export class Config {
13 readonly rootSection = "rust-analyzer"; 14 readonly rootSection = "rust-analyzer";
14 private readonly requiresReloadOpts = [ 15 private readonly requiresReloadOpts = [
15 "serverPath", 16 "serverPath",
17 "server",
16 "cargo", 18 "cargo",
17 "procMacro", 19 "procMacro",
18 "files", 20 "files",
@@ -92,6 +94,7 @@ export class Config {
92 } 94 }
93 95
94 get serverPath() { return this.get<null | string>("serverPath"); } 96 get serverPath() { return this.get<null | string>("serverPath"); }
97 get serverExtraEnv() { return this.get<Env | null>("server.extraEnv") ?? {}; }
95 get channel() { return this.get<UpdatesChannel>("updates.channel"); } 98 get channel() { return this.get<UpdatesChannel>("updates.channel"); }
96 get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); } 99 get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }
97 get traceExtension() { return this.get<boolean>("trace.extension"); } 100 get traceExtension() { return this.get<boolean>("trace.extension"); }
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index d39864d33..e7585184b 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -24,7 +24,7 @@ export class Ctx {
24 serverPath: string, 24 serverPath: string,
25 cwd: string, 25 cwd: string,
26 ): Promise<Ctx> { 26 ): Promise<Ctx> {
27 const client = createClient(serverPath, cwd); 27 const client = createClient(serverPath, cwd, config.serverExtraEnv);
28 28
29 const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); 29 const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
30 extCtx.subscriptions.push(statusBar); 30 extCtx.subscriptions.push(statusBar);