mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
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", } } ] } ```
This commit is contained in:
commit
bc1b0bfa7f
4 changed files with 50 additions and 6 deletions
|
@ -949,6 +949,29 @@ Or it is possible to specify vars more granularly:
|
||||||
You can use any valid regular expression as a mask.
|
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.
|
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
|
==== 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.
|
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.
|
||||||
|
|
|
@ -328,6 +328,15 @@
|
||||||
"items": {
|
"items": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"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": {
|
"mask": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Runnable name mask"
|
"description": "Runnable name mask"
|
||||||
|
|
|
@ -6,10 +6,12 @@ import type { Env } from "./client";
|
||||||
import { log } from "./util";
|
import { log } from "./util";
|
||||||
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
|
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
|
||||||
|
|
||||||
export type RunnableEnvCfg =
|
export type RunnableEnvCfgItem = {
|
||||||
| undefined
|
mask?: string;
|
||||||
| Record<string, string>
|
env: Record<string, string>;
|
||||||
| { mask?: string; env: Record<string, string> }[];
|
platform?: string | string[];
|
||||||
|
};
|
||||||
|
export type RunnableEnvCfg = undefined | Record<string, string> | RunnableEnvCfgItem[];
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
readonly extensionId = "rust-lang.rust-analyzer";
|
readonly extensionId = "rust-lang.rust-analyzer";
|
||||||
|
|
|
@ -5,7 +5,7 @@ import * as tasks from "./tasks";
|
||||||
|
|
||||||
import type { CtxInit } from "./ctx";
|
import type { CtxInit } from "./ctx";
|
||||||
import { makeDebugConfig } from "./debug";
|
import { makeDebugConfig } from "./debug";
|
||||||
import type { Config, RunnableEnvCfg } from "./config";
|
import type { Config, RunnableEnvCfg, RunnableEnvCfgItem } from "./config";
|
||||||
import { unwrapUndefinable } from "./undefinable";
|
import { unwrapUndefinable } from "./undefinable";
|
||||||
|
|
||||||
const quickPickButtons = [
|
const quickPickButtons = [
|
||||||
|
@ -112,11 +112,21 @@ export function prepareEnv(
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(env, process.env as { [key: string]: string });
|
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 (runnableEnvCfg) {
|
||||||
if (Array.isArray(runnableEnvCfg)) {
|
if (Array.isArray(runnableEnvCfg)) {
|
||||||
for (const it of 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);
|
Object.assign(env, it.env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue