about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-28 07:03:09 +0000
committerbors <bors@rust-lang.org>2023-07-28 07:03:09 +0000
commitbc1b0bfa7fd8188e207976485a841dc6c37b4f94 (patch)
treeda30a4ca923cb00a14d7be839c2d0060c28add23 /editors/code/src
parentb64e5b3919b24bc784f36248e6e1f921ee7bb71b (diff)
parent08b3b2a56db77d56cdf0b6a8a23b8f93f92dae4f (diff)
downloadrust-bc1b0bfa7fd8188e207976485a841dc6c37b4f94.tar.gz
rust-bc1b0bfa7fd8188e207976485a841dc6c37b4f94.zip
Auto merge of #15308 - vsrs:runnable_env_per_platform, r=HKalbasi
Runnable env per platform

This PR adds an option to specify runnables `env` per platform (win32, linux, etc.):
```
{
    "rust-analyzer.runnables.extraEnv": [
            {
                "platform": "win32",
                "env": {
                    "SCITER_BIN_FOLDER": "C:\\Projects\\3rd\\sciter-js-sdk\\bin\\windows\\x64",
                }
            },
            {
                "platform":["linux","darwin"],
                "env": {
                    "SCITER_BIN_FOLDER": "/home/vit/Projects/sciter/sciter-js-sdk/bin/linux/x64",
                }
            }
        ]
}
```
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts10
-rw-r--r--editors/code/src/run.ts14
2 files changed, 18 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..57881803a6a 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -5,7 +5,7 @@ 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";
 
 const quickPickButtons = [
@@ -112,11 +112,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);
                 }
             }