From 3468b093bd01e2cebba7964b48c9cef9ceb9e70b Mon Sep 17 00:00:00 2001 From: vsrs Date: Tue, 18 Jul 2023 17:51:57 +0700 Subject: [PATCH 1/3] Platform specific runnables env --- editors/code/package.json | 9 +++++++++ editors/code/src/config.ts | 10 ++++++---- editors/code/src/run.ts | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index ffb5dd9079a..6913841b3f7 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -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" 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 - | { mask?: string; env: Record }[]; +export type RunnableEnvCfgItem = { + mask?: string; + env: Record; + platform?: string | string[]; +}; +export type RunnableEnvCfg = undefined | Record | 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); } } From 7f29f016f3330b12b41f313c2b724063a2bd23d4 Mon Sep 17 00:00:00 2001 From: vsrs Date: Tue, 18 Jul 2023 17:58:51 +0700 Subject: [PATCH 2/3] Add docs --- docs/user/manual.adoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 31035c4b729..6d9234538d1 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -952,6 +952,29 @@ Or it is possible to specify vars more granularly: You can use any valid regular expression as a mask. Also note that a full runnable name is something like *run bin_or_example_name*, *test some::mod::test_name* or *test-mod some::mod*, so it is possible to distinguish binaries, single tests, and test modules with this masks: `"^run"`, `"^test "` (the trailing space matters!), and `"^test-mod"` respectively. +If needed, you can set different values for different platforms: +```jsonc +"rust-analyzer.runnables.extraEnv": [ + { + "platform": "win32", // windows only + env: { + "APP_DATA": "windows specific data" + } + }, + { + "platform": ["linux"], + "env": { + "APP_DATA": "linux data", + } + }, + { // for all platforms + "env": { + "APP_COMMON_DATA": "xxx", + } + } +] +``` + ==== Compiler feedback from external commands Instead of relying on the built-in `cargo check`, you can configure Code to run a command in the background and use the `$rustc-watch` problem matcher to generate inline error markers from its output. From 08b3b2a56db77d56cdf0b6a8a23b8f93f92dae4f Mon Sep 17 00:00:00 2001 From: vsrs Date: Tue, 18 Jul 2023 18:06:20 +0700 Subject: [PATCH 3/3] Fix lint --- editors/code/src/run.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index 8d468141d53..57881803a6a 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -7,7 +7,6 @@ import type { CtxInit } from "./ctx"; import { makeDebugConfig } from "./debug"; 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." },