Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3468b09

Browse files
committed
Platform specific runnables env
1 parent cc2f0ec commit 3468b09

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

editors/code/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@
325325
"items": {
326326
"type": "object",
327327
"properties": {
328+
"platform": {
329+
"type": [
330+
"null",
331+
"string",
332+
"array"
333+
],
334+
"default": null,
335+
"markdownDescription": "Platform(s) filter like \"win32\" or [\"linux\", \"win32\"]. See [process.platform](https://nodejs.org/api/process.html#processplatform) values."
336+
},
328337
"mask": {
329338
"type": "string",
330339
"description": "Runnable name mask"

editors/code/src/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import type { Env } from "./client";
66
import { log } from "./util";
77
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
88

9-
export type RunnableEnvCfg =
10-
| undefined
11-
| Record<string, string>
12-
| { mask?: string; env: Record<string, string> }[];
9+
export type RunnableEnvCfgItem = {
10+
mask?: string;
11+
env: Record<string, string>;
12+
platform?: string | string[];
13+
};
14+
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[];
1315

1416
export class Config {
1517
readonly extensionId = "rust-lang.rust-analyzer";

editors/code/src/run.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import * as tasks from "./tasks";
55

66
import type { CtxInit } from "./ctx";
77
import { makeDebugConfig } from "./debug";
8-
import type { Config, RunnableEnvCfg } from "./config";
8+
import type { Config, RunnableEnvCfg, RunnableEnvCfgItem } from "./config";
99
import { unwrapUndefinable } from "./undefinable";
10+
import { string } from "vscode-languageclient/lib/common/utils/is";
1011

1112
const quickPickButtons = [
1213
{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configuration." },
@@ -112,11 +113,21 @@ export function prepareEnv(
112113
}
113114

114115
Object.assign(env, process.env as { [key: string]: string });
116+
const platform = process.platform;
117+
118+
const checkPlatform = (it: RunnableEnvCfgItem) => {
119+
if (it.platform) {
120+
const platforms = Array.isArray(it.platform) ? it.platform : [it.platform];
121+
return platforms.indexOf(platform) >= 0;
122+
}
123+
return true;
124+
};
115125

116126
if (runnableEnvCfg) {
117127
if (Array.isArray(runnableEnvCfg)) {
118128
for (const it of runnableEnvCfg) {
119-
if (!it.mask || new RegExp(it.mask).test(runnable.label)) {
129+
const masked = !it.mask || new RegExp(it.mask).test(runnable.label);
130+
if (masked && checkPlatform(it)) {
120131
Object.assign(env, it.env);
121132
}
122133
}

0 commit comments

Comments
 (0)