mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Add an option for extra env vars in the Code extension
This commit is contained in:
parent
e7d2b5888b
commit
f7f6ac3554
4 changed files with 21 additions and 3 deletions
|
@ -283,6 +283,14 @@
|
||||||
"default": null,
|
"default": null,
|
||||||
"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"
|
"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"
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.server.extraEnv": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"object"
|
||||||
|
],
|
||||||
|
"default": null,
|
||||||
|
"markdownDescription": "Extra environment variables that will be passed to the rust-analyzer executable. Useful for passing e.g. `RA_LOG` for debugging."
|
||||||
|
},
|
||||||
"rust-analyzer.trace.server": {
|
"rust-analyzer.trace.server": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"scope": "window",
|
"scope": "window",
|
||||||
|
|
|
@ -6,6 +6,10 @@ import { DocumentSemanticsTokensSignature, DocumentSemanticsTokensEditsSignature
|
||||||
import { assert } from './util';
|
import { assert } from './util';
|
||||||
import { WorkspaceEdit } from 'vscode';
|
import { WorkspaceEdit } from 'vscode';
|
||||||
|
|
||||||
|
export interface Env {
|
||||||
|
[name: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
function renderCommand(cmd: ra.CommandLink) {
|
function renderCommand(cmd: ra.CommandLink) {
|
||||||
return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`;
|
return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`;
|
||||||
}
|
}
|
||||||
|
@ -27,14 +31,17 @@ async function semanticHighlightingWorkaround<R, F extends (...args: any[]) => v
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createClient(serverPath: string, cwd: string): lc.LanguageClient {
|
export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc.LanguageClient {
|
||||||
// '.' Is the fallback if no folder is open
|
// '.' Is the fallback if no folder is open
|
||||||
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
// 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.
|
// It might be a good idea to test if the uri points to a file.
|
||||||
|
|
||||||
|
const newEnv = Object.assign({}, process.env);
|
||||||
|
Object.assign(newEnv, extraEnv);
|
||||||
|
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
command: serverPath,
|
command: serverPath,
|
||||||
options: { cwd },
|
options: { cwd, env: newEnv },
|
||||||
};
|
};
|
||||||
const serverOptions: lc.ServerOptions = {
|
const serverOptions: lc.ServerOptions = {
|
||||||
run,
|
run,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import { Env } from './client';
|
||||||
import { log } from "./util";
|
import { log } from "./util";
|
||||||
|
|
||||||
export type UpdatesChannel = "stable" | "nightly";
|
export type UpdatesChannel = "stable" | "nightly";
|
||||||
|
@ -13,6 +14,7 @@ export class Config {
|
||||||
readonly rootSection = "rust-analyzer";
|
readonly rootSection = "rust-analyzer";
|
||||||
private readonly requiresReloadOpts = [
|
private readonly requiresReloadOpts = [
|
||||||
"serverPath",
|
"serverPath",
|
||||||
|
"server",
|
||||||
"cargo",
|
"cargo",
|
||||||
"procMacro",
|
"procMacro",
|
||||||
"files",
|
"files",
|
||||||
|
@ -92,6 +94,7 @@ export class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
get serverPath() { return this.get<null | string>("serverPath"); }
|
get serverPath() { return this.get<null | string>("serverPath"); }
|
||||||
|
get serverExtraEnv() { return this.get<Env | null>("server.extraEnv") ?? {}; }
|
||||||
get channel() { return this.get<UpdatesChannel>("updates.channel"); }
|
get channel() { return this.get<UpdatesChannel>("updates.channel"); }
|
||||||
get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }
|
get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }
|
||||||
get traceExtension() { return this.get<boolean>("trace.extension"); }
|
get traceExtension() { return this.get<boolean>("trace.extension"); }
|
||||||
|
|
|
@ -24,7 +24,7 @@ export class Ctx {
|
||||||
serverPath: string,
|
serverPath: string,
|
||||||
cwd: string,
|
cwd: string,
|
||||||
): Promise<Ctx> {
|
): Promise<Ctx> {
|
||||||
const client = createClient(serverPath, cwd);
|
const client = createClient(serverPath, cwd, config.serverExtraEnv);
|
||||||
|
|
||||||
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||||
extCtx.subscriptions.push(statusBar);
|
extCtx.subscriptions.push(statusBar);
|
||||||
|
|
Loading…
Reference in a new issue