vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

[Bug] Unable to select a launch target from a workspace file when .vscode/launch.json exists

Open arghness opened this issue 4 months ago • 3 comments

Brief Issue Summary

If I have a "launch {}" section in my workspace file, and a .vscode/launch.json file, the "Run and Debug" tab lists all the launch targets from both sources in the pulldown.

However, if I try to debug a ctest target from the "Testing" tab, when it provides a pulldown to select a target, it shows duplicate targets from .vscode/launch.json. If I remove .vscode/launch.json it will show targets from the workspace file.

This also applies to the new setting "cmake.ctest.debugLaunchTarget", It won't allow me to use a target from the workspace file, if .vscode/launch.json is present.

Workspace showing the issue (please open the workspace file, not the folder): ctest_issue.zip

Run and debug tab: Image

Pulldown after pressing "Debug Test" button on "test1": Image This shows the targets from launch.json twice, but says 2 of them are in the workspace, from the path underneath. If I try to select one from the workspace, it actually selects one from launch.json.

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.104.3",
  "cmtVersion": "1.21.36",
....
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "always",
      "configureOnOpen": false
    }
  ]
}

Debug Log

N/A

Additional Information

No response

arghness avatar Oct 08 '25 22:10 arghness

Hi @arghness, thanks for reporting issue here! We can reproduce this issue on VS Code 1.104.3 + CMake tools 1.21.36 version. Repro Steps:

  1. Download the attached project (ctest_issue.zip) and open it with "Open Workspace from File".
  2. Press F1, run command "CMake: Configure".
  3. Open Testing, click on "Debug Test", observe the result.
  4. Choose targets and observe the results.

Details please see following video: Image

FYI: @gcampbell-msft

yanghhhhhhh avatar Oct 09 '25 08:10 yanghhhhhhh

I'm not familiar with the VSCode extension API, but I did a little investigation.

The issue seems to be in src/ctest.ts lines 1163 and 1167:

        const launchConfig = vscode.workspace.getConfiguration(
            'launch',
            workspaceFolder.uri
        );
        const workspaceLaunchConfig = vscode.workspace.workspaceFile ? vscode.workspace.getConfiguration(
            'launch',
            vscode.workspace.workspaceFile
        ) : undefined;

The "scope" parameter for vscode.workspace.getConfiguration doesn't seem to do what's expected here.

In the scenario from the ctest_issue.zip in the original post, if I remove "vscode.workspace.workspaceFIle" from the second call to vscode.workspace.getConfiguration, it will give the correct 4 launch configurations (2 from the first call, 2 from the second).

However, if I then remove .vscode/launch.json , the first call to vscode.workspace.getConfiguration also returns the 2 launch configurations from the workspace file, so we end up with the workspace launch targets being duplicated in the pulldown.

arghness avatar Oct 09 '25 19:10 arghness

Thank you for the additional information.

yanghhhhhhh avatar Oct 10 '25 01:10 yanghhhhhhh