diff --git a/CHANGELOG.md b/CHANGELOG.md index f24983434c..e08aae5e32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.11 Improvements: - Fix build Error: EMFILE: too many open files. [#2288](https://github.com/microsoft/vscode-cmake-tools/issues/2288) [@FrogTheFrog](https://github.com/FrogTheFrog) +- Add commands to get preset names. [PR #2433](https://github.com/microsoft/vscode-cmake-tools/pull/2433) Bug Fixes: - `Clean All Projects` menu item builds rather than cleans. [#2460](https://github.com/microsoft/vscode-cmake-tools/issues/2460) diff --git a/docs/cmake-settings.md b/docs/cmake-settings.md index 45989b781e..baeca79511 100644 --- a/docs/cmake-settings.md +++ b/docs/cmake-settings.md @@ -89,6 +89,9 @@ Supported commands for substitution: |`cmake.tasksBuildCommand`|The CMake command used to build your project based on the currently selected Kit + Variant + Target. Suitable for use within `tasks.json`.| |`cmake.activeFolderName`|The name of the active folder (e.g. in a multi-root workspace)| |`cmake.activeFolderPath`|The asolute path of the active folder (e.g. in a multi-root workspace)| +|`cmake.activeConfigurePresetName`|The name of the active configure preset.| +|`cmake.activeBuildPresetName`|The name of the active build preset.| +|`cmake.activeTestPresetName`|The name of the active test preset.| ## Next steps diff --git a/package.json b/package.json index 01323f742e..0b45fbf409 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,9 @@ "activationEvents": [ "onCommand:cmake.activeFolderName", "onCommand:cmake.activeFolderPath", + "onCommand:cmake.activeConfigurePresetName", + "onCommand:cmake.activeBuildPresetName", + "onCommand:cmake.activeTestPresetName", "onCommand:cmake.build", "onCommand:cmake.buildAll", "onCommand:cmake.buildWithTarget", diff --git a/src/extension.ts b/src/extension.ts index 1fe637faa0..7206107b0e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1457,6 +1457,21 @@ class ExtensionManager implements vscode.Disposable { return false; } + activeConfigurePresetName(): string { + telemetry.logEvent("substitution", { command: "activeConfigurePresetName" }); + return this.folders.activeFolder?.cmakeTools.configurePreset?.name || ''; + } + + activeBuildPresetName(): string { + telemetry.logEvent("substitution", { command: "activeBuildPresetName" }); + return this.folders.activeFolder?.cmakeTools.buildPreset?.name || ''; + } + + activeTestPresetName(): string { + telemetry.logEvent("substitution", { command: "activeTestPresetName" }); + return this.folders.activeFolder?.cmakeTools.testPreset?.name || ''; + } + /** * Opens CMakePresets.json at the root of the project. Creates one if it does not exist. */ @@ -1629,6 +1644,9 @@ async function setup(context: vscode.ExtensionContext, progress?: ProgressHandle const funs: (keyof ExtensionManager)[] = [ 'activeFolderName', 'activeFolderPath', + 'activeConfigurePresetName', + 'activeBuildPresetName', + 'activeTestPresetName', "useCMakePresets", "openCMakePresets", 'addConfigurePreset',