Skip to content

Commit 2d92ba3

Browse files
authored
documentation updates for variable substitution (#4870)
1 parent 2d772e9 commit 2d92ba3

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Features:
2323
- Add `cmake.outlineViewType` setting to toggle the Project Outline between a flat list view and the prior hierarchical tree view that shows each CMake project separately. [#3799](https://github.com/microsoft/vscode-cmake-tools/issues/3799) [#4538](https://github.com/microsoft/vscode-cmake-tools/pull/4538) [@ar1m4n](https://github.com/ar1m4n)
2424

2525
Improvements:
26+
- Clarify variable substitution scope in docs for `settings.json` vs generic VS Code `tasks.json`/`launch.json`, including when to use `${command:cmake.*}` and why `${buildKit}`, `${generator}`, and `${config:cmake.configureArgs}` may not expand as expected in tasks. [#4010](https://github.com/microsoft/vscode-cmake-tools/issues/4010)
2627
- Improve CMake syntax highlighting: extend variable recognition with compiler/toolchain families and add scoped property command colorization for `set_property`, `get_property`, `set_target_properties`, and related commands. [#4527](https://github.com/microsoft/vscode-cmake-tools/pull/4527) [@pboettch](https://github.com/pboettch)
2728
- Run tests sequentially in alphabetical order (matching the Test Explorer display order) when `cmake.ctest.allowParallelJobs` is disabled. [#4829](https://github.com/microsoft/vscode-cmake-tools/issues/4829)
2829
- Document how to configure `cmake.debugConfig.visualizerFile` to use custom Natvis files with quick debugging, without requiring a `launch.json`. [#4616](https://github.com/microsoft/vscode-cmake-tools/issues/4616)

docs/cmake-settings.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,22 @@ Options that support substitution, in the table below, allow variable references
104104

105105
## Variable substitution
106106

107-
Some settings support the replacement of special values in their string value by using a `${variable}` syntax. The following built-in variables are expanded:
107+
Some settings support the replacement of special values in their string value by using a `${variable}` syntax.
108+
109+
### Where substitution works
110+
111+
Use this quick rule to avoid confusion:
112+
113+
- CMake Tools `${...}` variables in this section (for example `${buildKit}` and `${generator}`) are expanded only when CMake Tools reads supported `cmake.*` settings from `settings.json`.
114+
- Generic VS Code `tasks.json` and `launch.json` fields are resolved by VS Code, not by CMake Tools. In those fields, use VS Code variables (for example `${workspaceFolder}`) or command substitutions such as `${command:cmake.buildKit}`.
115+
- `${config:cmake.*}` in `tasks.json`/`launch.json` returns the raw setting value. It does not apply a second CMake Tools substitution pass.
116+
117+
Example:
118+
119+
- In a shell task command, `${buildKit}` and `${generator}` are not expanded.
120+
- In a shell task command, `${command:cmake.buildKit}` is expanded.
121+
122+
The following built-in variables are expanded in supported `cmake.*` settings only. None of these are expanded in generic VS Code shell or process task commands. Use the `${command:cmake.*}` forms listed under [Command substitution](#command-substitution) for those contexts.
108123

109124
| Variable | Expansion |
110125
|---------|---------|
@@ -136,7 +151,9 @@ Variant options are expanded using the `${variant:VARIANTNAME}` syntax, where th
136151

137152
### Command substitution
138153

139-
CMake Tools can expand VS Code commands. For example, you can expand the path to the launch target by using the syntax `${command:cmake.launchTargetPath}`
154+
CMake Tools can expand VS Code commands. For example, you can expand the path to the launch target by using the syntax `${command:cmake.launchTargetPath}`.
155+
156+
This form is the recommended way to get CMake Tools values in generic `tasks.json` or `launch.json` fields.
140157

141158
Be careful with long-running commands because it isn't specified when, or how many times, CMake Tools will execute a command for a given expansion.
142159

docs/tasks.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ You can create a configure task from the VS Code command pallette by running the
33

44
![Configure a task](images/configure_task.png)
55

6+
## Variable substitution in `tasks.json`
7+
8+
When authoring generic VS Code shell/process tasks, `${buildKit}` and `${generator}` are not expanded because those are CMake Tools setting substitutions, not VS Code task variables.
9+
10+
Use command substitutions in `tasks.json` instead:
11+
12+
- `${command:cmake.buildKit}` for the active kit name.
13+
- `${command:cmake.buildType}` for the active build type.
14+
- `${command:cmake.tasksBuildCommand}` for a full CMake build command.
15+
16+
If you use `${config:cmake.configureArgs}` in `tasks.json`, VS Code returns the configured value as-is. CMake Tools substitution is not applied again in that context.
17+
618
By selecting "CMake: configure" template, if you are not using presets, this task will be generated in `tasks.json` file:
719

820

0 commit comments

Comments
 (0)