Skip to content

Fix select preset/kit commands to return strings for task variable substitution#4825

Merged
Omotola merged 5 commits intomainfrom
copilot/fix-error-selecting-active-config
Mar 20, 2026
Merged

Fix select preset/kit commands to return strings for task variable substitution#4825
Omotola merged 5 commits intomainfrom
copilot/fix-error-selecting-active-config

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

This change addresses item #4239

This changes visible behavior of preset and kit selection commands when used as ${command:...} variables

The following changes are proposed:

  • Change selectConfigurePreset, selectBuildPreset, selectTestPreset, selectPackagePreset, selectWorkflowPreset, and selectKit in ExtensionManager to return Promise<string> (selected name) instead of Promise<boolean>
  • Return empty string on cancellation/failure, selected preset/kit name on success
  • Add CHANGELOG entry for the fix

The purpose of this change

Using ${command:cmake.selectConfigurePreset} in tasks.json fails with:

Cannot substitute command variable 'cmake.selectConfigurePreset' because command did not return a result of type string.

VS Code's command variable substitution requires a string return value. These commands returned boolean.

Other Notes/Information

The change is backward-compatible: all internal callers use truthiness checks (!didChoosePreset), and empty string is falsy / non-empty string is truthy — identical semantics to false/true.

// tasks.json — now works without error
{
    "label": "set active config",
    "command": "${command:cmake.selectConfigurePreset}"
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Using ${command:cmake.selectConfigurePreset} in tasks.json pops up error when selecting already active configuration</issue_title>
<issue_description>### Brief Issue Summary

Hi,

I have a vscode task that I use to change the current configuration preset:

{
    "label": "set active config",
    "group": "build",
    "command": "${command:cmake.selectConfigurePreset}"
}

I can toggle without issues between configurations Release, Debug. The issue arises when I select the already active configuration, then I get this error:
Cannot substitute command variable 'cmake.selectConfigurePreset' because command did not return a result of type string.

How to reproduce

  1. Run the task, select "X" configuration
  2. Run the task again, select the same "X" configuration

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.95.3",
  "cmtVersion": "1.19.52",
  "configurations": [
    {
      "folder": "/opt/my-project",
      "cmakeVersion": "3.27.0",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": true,
      "compilers": {
        "C": "/usr/bin/gcc",
        "CXX": "/usr/bin/g++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 34,
    "executablesCount": 3,
    "librariesCount": 3,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log

Additional Information

No response</issue_description>

<agent_instructions>fix this issue in a pr and cite issue 4239 in the change log</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

The select commands (selectConfigurePreset, selectBuildPreset,
selectTestPreset, selectPackagePreset, selectWorkflowPreset, selectKit)
now return the selected preset/kit name as a string instead of a boolean.
This allows them to work correctly as ${command:...} variables in
tasks.json, which require a string result.

Empty string is returned on cancellation (falsy), so all existing
callers that check truthiness continue to work correctly.

Fixes #4239

Co-authored-by: Omotola <8052624+Omotola@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error when selecting already active configuration Fix select preset/kit commands to return strings for task variable substitution Mar 17, 2026
Copilot AI requested a review from Omotola March 17, 2026 23:13
@Omotola
Copy link
Copy Markdown
Contributor

Omotola commented Mar 18, 2026

validated locally:

Before fix - task doesn't execute, it gives an error:
image

After fix - task is executing as expected:
image

@Omotola Omotola marked this pull request as ready for review March 18, 2026 21:50
@hanniavalera
Copy link
Copy Markdown
Contributor

@copilot fix the CHANGELOG.md as it was not rebased/merged properly against main, do not change the PR description

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-cmake-tools/sessions/7e265975-65ca-40bf-87fc-2d06d58ae0a5
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot fix the CHANGELOG.md as it was not rebased/merged properly against main, do not change the PR description

Resolved the merge conflict markers in CHANGELOG.md — both entries (ours for #4239 and the #4343 fix from main) are now properly included. See commit d1f19b6.

Copilot AI requested a review from hanniavalera March 20, 2026 17:37
@Omotola Omotola enabled auto-merge (squash) March 20, 2026 18:42
@Omotola Omotola merged commit e5ad7b2 into main Mar 20, 2026
4 checks passed
@Omotola Omotola deleted the copilot/fix-error-selecting-active-config branch March 20, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using ${command:cmake.selectConfigurePreset} in tasks.json pops up error when selecting already active configuration

4 participants