Add environment to runnable lsp extension

This commit is contained in:
Lukas Wirth 2024-07-06 16:15:06 +02:00
parent f2afcb874e
commit fcddcf2ee5
7 changed files with 85 additions and 33 deletions

View file

@ -235,22 +235,46 @@ type RunnableShell = {
args: ShellRunnableArgs;
};
export type CommonRunnableArgs = {
/**
* Environment variables to set before running the command.
*/
environment: Record<string, string>;
/**
* The working directory to run the command in.
*/
cwd: string;
};
export type ShellRunnableArgs = {
kind: string;
program: string;
args: string[];
cwd: string;
};
} & CommonRunnableArgs;
export type CargoRunnableArgs = {
/**
* The workspace root directory of the cargo project.
*/
workspaceRoot?: string;
/**
* The cargo command to run.
*/
cargoArgs: string[];
cwd: string;
/**
* Extra arguments to pass to cargo.
*/
// What is the point of this when cargoArgs exists?
cargoExtraArgs: string[];
/**
* Arguments to pass to the executable, these will be passed to the command after a `--` argument.
*/
executableArgs: string[];
expectTest?: boolean;
/**
* Command to execute instead of `cargo`.
*/
overrideCargo?: string;
};
} & CommonRunnableArgs;
export type RunnablesParams = {
textDocument: lc.TextDocumentIdentifier;

View file

@ -66,9 +66,12 @@ export class RunnableQuickPick implements vscode.QuickPickItem {
}
}
export function prepareBaseEnv(): Record<string, string> {
export function prepareBaseEnv(base?: Record<string, string>): Record<string, string> {
const env: Record<string, string> = { RUST_BACKTRACE: "short" };
Object.assign(env, process.env as { [key: string]: string });
Object.assign(env, process.env);
if (base) {
Object.assign(env, base);
}
return env;
}
@ -77,12 +80,7 @@ export function prepareEnv(
runnableArgs: ra.CargoRunnableArgs,
runnableEnvCfg: RunnableEnvCfg,
): Record<string, string> {
const env = prepareBaseEnv();
if (runnableArgs.expectTest) {
env["UPDATE_EXPECT"] = "1";
}
const env = prepareBaseEnv(runnableArgs.environment);
const platform = process.platform;
const checkPlatform = (it: RunnableEnvCfgItem) => {