diff options
| author | vsrs <vit@conrlab.com> | 2023-07-18 17:51:57 +0700 |
|---|---|---|
| committer | vsrs <vit@conrlab.com> | 2023-07-18 17:51:57 +0700 |
| commit | 3468b093bd01e2cebba7964b48c9cef9ceb9e70b (patch) | |
| tree | 03db107b7a69c35854cc96d2ff5361e520ab6a03 /editors/code/src | |
| parent | cc2f0ec32cdd86c33e8a5c41dfbc842ad43f5a97 (diff) | |
| download | rust-3468b093bd01e2cebba7964b48c9cef9ceb9e70b.tar.gz rust-3468b093bd01e2cebba7964b48c9cef9ceb9e70b.zip | |
Platform specific runnables env
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/config.ts | 10 | ||||
| -rw-r--r-- | editors/code/src/run.ts | 15 |
2 files changed, 19 insertions, 6 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index a047f9659a9..0e64054c11d 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -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"; diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index c893d390554..8d468141d53 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -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); } } |
