Skip to content

Commit ffe7f11

Browse files
CopilothanniavaleraCopilot
authored
Complete Bookmarks context menu with full target action parity (#4810)
* Initial plan * feat: complete Bookmarks context menu with full target action parity (#4788) - Enrich BookmarkNode.contextValue with target metadata (canBuild, canRun, isDefault, isLaunch, specific type) from the live source TargetNode - Fix setDefaultTarget, setLaunchTarget, revealInCMakeLists handlers to accept BookmarkNode via resolveTargetNode - Add missing bookmark context menu entries: Set Build Target, Set Launch/Debug Target, Open CMakeLists.txt, Run Utility Target - Refine existing bookmark menu entries with proper when clauses Co-authored-by: hanniavalera <[email protected]> * fixing bug that viewItem =~ /isDefault=/ is too broad and matches isDefault=false on unresolved bookmarks Co-authored-by: Copilot Autofix powered by AI <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hanniavalera <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]>
1 parent 4178c47 commit ffe7f11

4 files changed

Lines changed: 63 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Features:
1313
- Add `cmake.setBuildTargetSameAsLaunchTarget` setting to automatically set the build target when the launch/debug target is changed. [#4519](https://github.com/microsoft/vscode-cmake-tools/pull/4519) [@nikita-karatun](https://github.com/nikita-karatun)
1414
- Add `cmake.additionalBuildProblemMatchers` setting to define custom problem matchers for build output. Supports tools like clang-tidy, PCLint Plus, cppcheck, or custom scripts integrated via `add_custom_command`/`add_custom_target`. [#4077](https://github.com/microsoft/vscode-cmake-tools/issues/4077)
1515
- Support `targetName` argument for launch-target command substitutions (`cmake.launchTargetPath`, etc.) via `${input:...}` variables, enabling build-before-run for non-active executable targets without changing the active launch target. [#4656](https://github.com/microsoft/vscode-cmake-tools/issues/4656)
16+
- Complete Bookmarks context menu with "Set Build Target", "Set Launch/Debug Target", "Open CMakeLists.txt", and "Run Utility Target" actions to match the Project Outline. [#4788](https://github.com/microsoft/vscode-cmake-tools/issues/4788)
1617
- Relax `intelliSenseMode` validation in CMake Presets. [#4815](https://github.com/microsoft/vscode-cmake-tools/issues/4815) [@halflifefan](https://github.com/halflifefan)
1718

1819
Improvements:

package.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,18 +2116,38 @@
21162116
},
21172117
{
21182118
"command": "cmake.outline.buildTarget",
2119-
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet",
2120-
"group": "bookmarkActions@1"
2119+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /canBuild=true/",
2120+
"group": "1_targetActions@1"
2121+
},
2122+
{
2123+
"command": "cmake.outline.runUtilityTarget",
2124+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /canRun=true/",
2125+
"group": "1_targetActions@2"
21212126
},
21222127
{
21232128
"command": "cmake.outline.debugTarget",
2124-
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet",
2125-
"group": "bookmarkActions@2"
2129+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /type=EXECUTABLE/",
2130+
"group": "1_targetActions@3"
21262131
},
21272132
{
21282133
"command": "cmake.outline.launchTarget",
2129-
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet",
2130-
"group": "bookmarkActions@3"
2134+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /type=EXECUTABLE/",
2135+
"group": "1_targetActions@4"
2136+
},
2137+
{
2138+
"command": "cmake.outline.revealInCMakeLists",
2139+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /isDefault=/ && viewItem =~ /canBuild=true|canRun=true/",
2140+
"group": "1_targetActions@5"
2141+
},
2142+
{
2143+
"command": "cmake.outline.setDefaultTarget",
2144+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /canRun=true|canBuild=true/ && viewItem =~ /isDefault=false/",
2145+
"group": "2_targetState@1"
2146+
},
2147+
{
2148+
"command": "cmake.outline.setLaunchTarget",
2149+
"when": "view == cmake.bookmarks && cmake:enableFullFeatureSet && viewItem =~ /type=EXECUTABLE/ && viewItem =~ /isLaunch=false/",
2150+
"group": "2_targetState@2"
21312151
}
21322152
],
21332153
"editor/title/context": [

src/extension.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,9 +2654,24 @@ async function setup(context: vscode.ExtensionContext, progress?: ProgressHandle
26542654
return runCommand('launchTarget', target.folder, target.name, target.sourceDir);
26552655
}
26562656
}),
2657-
vscode.commands.registerCommand('cmake.outline.setDefaultTarget', (what: TargetNode) => runCommand('setDefaultTarget', what.folder, what.name, what.sourceDir)),
2658-
vscode.commands.registerCommand('cmake.outline.setLaunchTarget', (what: TargetNode) => runCommand('selectLaunchTarget', what.folder, what.name, what.sourceDir)),
2659-
vscode.commands.registerCommand('cmake.outline.revealInCMakeLists', (what: TargetNode) => what.openInCMakeLists()),
2657+
vscode.commands.registerCommand('cmake.outline.setDefaultTarget', (what: TargetNode | BookmarkNode) => {
2658+
const target = resolveTargetNode(what);
2659+
if (target) {
2660+
return runCommand('setDefaultTarget', target.folder, target.name, target.sourceDir);
2661+
}
2662+
}),
2663+
vscode.commands.registerCommand('cmake.outline.setLaunchTarget', (what: TargetNode | BookmarkNode) => {
2664+
const target = resolveTargetNode(what);
2665+
if (target) {
2666+
return runCommand('selectLaunchTarget', target.folder, target.name, target.sourceDir);
2667+
}
2668+
}),
2669+
vscode.commands.registerCommand('cmake.outline.revealInCMakeLists', (what: TargetNode | BookmarkNode) => {
2670+
const target = resolveTargetNode(what);
2671+
if (target) {
2672+
return target.openInCMakeLists();
2673+
}
2674+
}),
26602675
vscode.commands.registerCommand('cmake.outline.runTest', (what: CTestTestNode) => runCommand('runTest', what.folder, what.testName, what.sourceDir)),
26612676
vscode.commands.registerCommand('cmake.outline.debugTest', (what: CTestTestNode) => runCommand('debugCTest', what.folder, what.testName, what.sourceDir)),
26622677
vscode.commands.registerCommand('cmake.outline.compileFile', (what: SourceFileNode) => runCommand('compileFile', what.filePath)),

src/ui/bookmarks.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,24 @@ export class BookmarkNode extends BaseNode {
4646
this.bookmark.projectName || localize('not.available', 'N/A'),
4747
this.bookmark.type,
4848
this.bookmark.folderName);
49-
item.contextValue = `nodeType=bookmark;type=${this.bookmark.type};bookmarked=true`;
49+
50+
// Build contextValue. For TARGET bookmarks with a live source node, propagate
51+
// target metadata (canBuild, canRun, isDefault, isLaunch, specific type) so
52+
// that the same context-menu actions available in the outline also appear here.
53+
if (this.bookmark.type === 'TARGET' && this.bookmark.sourceNode instanceof TargetNode) {
54+
const sourceItem = this.bookmark.sourceNode.getTreeItem();
55+
const sourceContext = sourceItem.contextValue || '';
56+
item.contextValue = sourceContext
57+
.replace(/nodeType=target/, 'nodeType=bookmark')
58+
+ ',bookmarked=true';
59+
} else if (this.bookmark.type === 'TARGET') {
60+
// Unresolved target bookmark — include default flags so the contextValue
61+
// structure is consistent but no actions that require a live node will match.
62+
item.contextValue = 'nodeType=bookmark,type=TARGET,bookmarked=true,canBuild=false,canRun=false,isDefault=false,isLaunch=false';
63+
} else {
64+
item.contextValue = `nodeType=bookmark,type=${this.bookmark.type},bookmarked=true`;
65+
}
66+
5067
item.iconPath = new vscode.ThemeIcon("bookmark");
5168
return item;
5269
}

0 commit comments

Comments
 (0)