diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-03 14:17:36 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-03 14:17:36 +0100 |
commit | 84891455832ba871e1c5a6908ac798b7627c0c70 (patch) | |
tree | a0f4fb16c857d759b9f95e5d9322080fe76101b5 /editors/code/src/debug.ts | |
parent | f51b0cfdd6c23dd57a0a11154179730171c0425d (diff) | |
parent | 188d24024cd2770822d3e525be3ea330e79625c8 (diff) |
Merge #5202
5202: Runnable env r=matklad a=vsrs
This PR adds on option to specify (in the settings.json) environment variables passed to the runnable.
The simplest way for all runnables in a bunch:
```jsonc
"rust-analyzer.runnableEnv": {
"RUN_SLOW_TESTS": "1"
}
```
Or it is possible to specify vars more granularly:
```jsonc
"rust-analyzer.runnableEnv": [
{
// "mask": null, // null mask means that this rule will be applied for all runnables
env: {
"APP_ID": "1",
"APP_DATA": "asdf"
}
},
{
"mask": "test_name",
"env": {
"APP_ID": "2", // overwrites only APP_ID
}
}
]
```
You can use any valid RegExp 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.
Fixes #4450
I suppose this info should be somewhere in the docs, but unsure where is the best place.
Co-authored-by: vsrs <[email protected]>
Diffstat (limited to 'editors/code/src/debug.ts')
-rw-r--r-- | editors/code/src/debug.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 61c12dbe0..bd92c5b6d 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts | |||
@@ -5,9 +5,10 @@ import * as ra from './lsp_ext'; | |||
5 | 5 | ||
6 | import { Cargo } from './toolchain'; | 6 | import { Cargo } from './toolchain'; |
7 | import { Ctx } from "./ctx"; | 7 | import { Ctx } from "./ctx"; |
8 | import { prepareEnv } from "./run"; | ||
8 | 9 | ||
9 | const debugOutput = vscode.window.createOutputChannel("Debug"); | 10 | const debugOutput = vscode.window.createOutputChannel("Debug"); |
10 | type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; | 11 | type DebugConfigProvider = (config: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; |
11 | 12 | ||
12 | export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<void> { | 13 | export async function makeDebugConfig(ctx: Ctx, runnable: ra.Runnable): Promise<void> { |
13 | const scope = ctx.activeRustEditor?.document.uri; | 14 | const scope = ctx.activeRustEditor?.document.uri; |
@@ -92,7 +93,8 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v | |||
92 | } | 93 | } |
93 | 94 | ||
94 | const executable = await getDebugExecutable(runnable); | 95 | const executable = await getDebugExecutable(runnable); |
95 | const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), debugOptions.sourceFileMap); | 96 | const env = prepareEnv(runnable, ctx.config.runnableEnv); |
97 | const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), env, debugOptions.sourceFileMap); | ||
96 | if (debugConfig.type in debugOptions.engineSettings) { | 98 | if (debugConfig.type in debugOptions.engineSettings) { |
97 | const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; | 99 | const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; |
98 | for (var key in settingsMap) { | 100 | for (var key in settingsMap) { |
@@ -121,7 +123,7 @@ async function getDebugExecutable(runnable: ra.Runnable): Promise<string> { | |||
121 | return executable; | 123 | return executable; |
122 | } | 124 | } |
123 | 125 | ||
124 | function getLldbDebugConfig(runnable: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { | 126 | function getLldbDebugConfig(runnable: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { |
125 | return { | 127 | return { |
126 | type: "lldb", | 128 | type: "lldb", |
127 | request: "launch", | 129 | request: "launch", |
@@ -130,11 +132,12 @@ function getLldbDebugConfig(runnable: ra.Runnable, executable: string, sourceFil | |||
130 | args: runnable.args.executableArgs, | 132 | args: runnable.args.executableArgs, |
131 | cwd: runnable.args.workspaceRoot, | 133 | cwd: runnable.args.workspaceRoot, |
132 | sourceMap: sourceFileMap, | 134 | sourceMap: sourceFileMap, |
133 | sourceLanguages: ["rust"] | 135 | sourceLanguages: ["rust"], |
136 | env | ||
134 | }; | 137 | }; |
135 | } | 138 | } |
136 | 139 | ||
137 | function getCppvsDebugConfig(runnable: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { | 140 | function getCppvsDebugConfig(runnable: ra.Runnable, executable: string, env: Record<string, string>, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { |
138 | return { | 141 | return { |
139 | type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", | 142 | type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", |
140 | request: "launch", | 143 | request: "launch", |
@@ -142,6 +145,7 @@ function getCppvsDebugConfig(runnable: ra.Runnable, executable: string, sourceFi | |||
142 | program: executable, | 145 | program: executable, |
143 | args: runnable.args.executableArgs, | 146 | args: runnable.args.executableArgs, |
144 | cwd: runnable.args.workspaceRoot, | 147 | cwd: runnable.args.workspaceRoot, |
145 | sourceFileMap: sourceFileMap, | 148 | sourceFileMap, |
149 | env, | ||
146 | }; | 150 | }; |
147 | } | 151 | } |