Platform specific runnables env
This commit is contained in:
parent
cc2f0ec32c
commit
3468b093bd
@ -325,6 +325,15 @@
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"platform": {
|
||||
"type": [
|
||||
"null",
|
||||
"string",
|
||||
"array"
|
||||
],
|
||||
"default": null,
|
||||
"markdownDescription": "Platform(s) filter like \"win32\" or [\"linux\", \"win32\"]. See [process.platform](https://nodejs.org/api/process.html#processplatform) values."
|
||||
},
|
||||
"mask": {
|
||||
"type": "string",
|
||||
"description": "Runnable name mask"
|
||||
|
@ -6,10 +6,12 @@ import type { Env } from "./client";
|
||||
import { log } from "./util";
|
||||
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
|
||||
|
||||
export type RunnableEnvCfg =
|
||||
| undefined
|
||||
| Record<string, string>
|
||||
| { mask?: string; env: Record<string, string> }[];
|
||||
export type RunnableEnvCfgItem = {
|
||||
mask?: string;
|
||||
env: Record<string, string>;
|
||||
platform?: string | string[];
|
||||
};
|
||||
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[];
|
||||
|
||||
export class Config {
|
||||
readonly extensionId = "rust-lang.rust-analyzer";
|
||||
|
@ -5,8 +5,9 @@ import * as tasks from "./tasks";
|
||||
|
||||
import type { CtxInit } from "./ctx";
|
||||
import { makeDebugConfig } from "./debug";
|
||||
import type { Config, RunnableEnvCfg } from "./config";
|
||||
import type { Config, RunnableEnvCfg, RunnableEnvCfgItem } from "./config";
|
||||
import { unwrapUndefinable } from "./undefinable";
|
||||
import { string } from "vscode-languageclient/lib/common/utils/is";
|
||||
|
||||
const quickPickButtons = [
|
||||
{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configuration." },
|
||||
@ -112,11 +113,21 @@ export function prepareEnv(
|
||||
}
|
||||
|
||||
Object.assign(env, process.env as { [key: string]: string });
|
||||
const platform = process.platform;
|
||||
|
||||
const checkPlatform = (it: RunnableEnvCfgItem) => {
|
||||
if (it.platform) {
|
||||
const platforms = Array.isArray(it.platform) ? it.platform : [it.platform];
|
||||
return platforms.indexOf(platform) >= 0;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if (runnableEnvCfg) {
|
||||
if (Array.isArray(runnableEnvCfg)) {
|
||||
for (const it of runnableEnvCfg) {
|
||||
if (!it.mask || new RegExp(it.mask).test(runnable.label)) {
|
||||
const masked = !it.mask || new RegExp(it.mask).test(runnable.label);
|
||||
if (masked && checkPlatform(it)) {
|
||||
Object.assign(env, it.env);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user