[Bug] Unable to select a launch target from a workspace file when .vscode/launch.json exists
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:
Pulldown after pressing "Debug Test" button on "test1":
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
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:
- Download the attached project (ctest_issue.zip) and open it with "Open Workspace from File".
- Press F1, run command "CMake: Configure".
- Open Testing, click on "Debug Test", observe the result.
- Choose targets and observe the results.
Details please see following video:
FYI: @gcampbell-msft
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.
Thank you for the additional information.