forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#12215 - listochkin:Support-variable-substitut…
…ion-in-vscode-settings, r=Veykril feat: Support variable substitution in VSCode settings Currently support a subset of [variables provided by VSCode](https://code.visualstudio.com/docs/editor/variables-reference) in `server.extraEnv` section of Rust-Analyzer settings: * `workspaceFolder` * `workspaceFolderBasename` * `cwd` * `execPath` * `pathSeparator` Also, this PR adds support for general environment variables resolution. You can declare environment variables and reference them from other variables like this: ```JSON "rust-analyzer.server.extraEnv": { "RUSTFLAGS": "-L${env:OPEN_XR_SDK_PATH}", "OPEN_XR_SDK_PATH": "${workspaceFolder}\\..\\OpenXR-SDK\\build\\src\\loader\\Release" }, ``` The order of variable declaration doesn't matter, you can reference variables before defining them. If the variable is not present in `extraEnv` section, VSCode will search for them in your environment. Missing variables will be replaced with empty string. Circular references won't be resolved and will be passed to rust-analyzer server process as is. Closes rust-lang#9626, but doesn't address use cases where people want to use values provided by `rustc` or `cargo`, such as `${targetTriple}` proposal rust-lang#11649
- Loading branch information
Showing
7 changed files
with
225 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as assert from 'assert'; | ||
import { Context } from '.'; | ||
import { substituteVariablesInEnv } from '../../src/config'; | ||
|
||
export async function getTests(ctx: Context) { | ||
await ctx.suite('Server Env Settings', suite => { | ||
suite.addTest('Replacing Env Variables', async () => { | ||
const envJson = { | ||
USING_MY_VAR: "${env:MY_VAR} test ${env:MY_VAR}", | ||
MY_VAR: "test" | ||
}; | ||
const expectedEnv = { | ||
USING_MY_VAR: "test test test", | ||
MY_VAR: "test" | ||
}; | ||
const actualEnv = await substituteVariablesInEnv(envJson); | ||
assert.deepStrictEqual(actualEnv, expectedEnv); | ||
}); | ||
|
||
suite.addTest('Circular dependencies remain as is', async () => { | ||
const envJson = { | ||
A_USES_B: "${env:B_USES_A}", | ||
B_USES_A: "${env:A_USES_B}", | ||
C_USES_ITSELF: "${env:C_USES_ITSELF}", | ||
D_USES_C: "${env:C_USES_ITSELF}", | ||
E_IS_ISOLATED: "test", | ||
F_USES_E: "${env:E_IS_ISOLATED}" | ||
}; | ||
const expectedEnv = { | ||
A_USES_B: "${env:B_USES_A}", | ||
B_USES_A: "${env:A_USES_B}", | ||
C_USES_ITSELF: "${env:C_USES_ITSELF}", | ||
D_USES_C: "${env:C_USES_ITSELF}", | ||
E_IS_ISOLATED: "test", | ||
F_USES_E: "test" | ||
}; | ||
const actualEnv = await substituteVariablesInEnv(envJson); | ||
assert.deepStrictEqual(actualEnv, expectedEnv); | ||
}); | ||
|
||
suite.addTest('Should support external variables', async () => { | ||
const envJson = { | ||
USING_EXTERNAL_VAR: "${env:TEST_VARIABLE} test ${env:TEST_VARIABLE}" | ||
}; | ||
const expectedEnv = { | ||
USING_EXTERNAL_VAR: "test test test" | ||
}; | ||
|
||
const actualEnv = await substituteVariablesInEnv(envJson); | ||
assert.deepStrictEqual(actualEnv, expectedEnv); | ||
}); | ||
|
||
suite.addTest('should support VSCode variables', async () => { | ||
const envJson = { | ||
USING_VSCODE_VAR: "${workspaceFolderBasename}" | ||
}; | ||
const actualEnv = await substituteVariablesInEnv(envJson); | ||
assert.deepStrictEqual(actualEnv.USING_VSCODE_VAR, 'code'); | ||
}); | ||
}); | ||
} |