Skip to content

Add editor context menu support for Razor nested file commands#13023

Merged
ToddGrun merged 3 commits intomainfrom
dev/toddgrun/nested_file_menu_support_in_editor
Apr 9, 2026
Merged

Add editor context menu support for Razor nested file commands#13023
ToddGrun merged 3 commits intomainfrom
dev/toddgrun/nested_file_menu_support_in_editor

Conversation

@ToddGrun
Copy link
Copy Markdown
Contributor

@ToddGrun ToddGrun commented Apr 8, 2026

Finishes work for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1903761 Earlier PRs in support of this ticket:
#12981
https://devdiv.visualstudio.com/DevDiv/_git/WebTools/pullrequest/725194
https://devdiv.visualstudio.com/DevDiv/_git/WebTools/pullrequest/725955

Add editor context menu commands for Razor nested files alongside the existing Solution Explorer commands. Uses VSCT CommandPlacements to share CSS/JS command IDs across both menus, and IVsMonitorSelection.GetCurrentSelection to resolve the active file (which tracks the active window frame, not just Solution Explorer tree selection).

Key changes:

  • Unified NestedFileCommandHandler serves both Solution Explorer and editor menus via shared command IDs and SelectionHelper for selection/UIContext queries
  • Added editor context menu group (grpidRazorNestedFilesEditor) on IDM_VS_CTXT_CODEWIN with CSS/JS commands placed via CommandPlacements
  • For .cs in editor: intercept standard ViewCode (F7) command via UsedCommands so the F7 keybinding indicator displays automatically. Handler yields (Supported=false) to fall through to default ViewCode when not in a Razor file
  • Added separate cmdidAddNestedCsFileEditor for the "Add .cs" case in editor, so it appears without the F7 keybinding when the .cs file doesn't exist
  • Added "View Page" command for navigating from nested files back to the parent Razor file, placed in editor, Solution Explorer, and CSS editor context menus
  • Extended UIContextRule to activate for nested files (.razor.* and .cshtml.*) in addition to .razor and .cshtml
  • ViewCodeCommandHandler (MEF F7 handler): returns Unavailable when .cs doesn't exist, excludes _Imports.razor and _ViewImports.cshtml, uses FileExistsHelper cache for per-keystroke performance
  • Added View_Page resource with translations, cleaned up unused Add_Code resource
  • Updated tests for new constructor signature and behavior

Finishes work for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1903761
Earlier PRs in support of this ticket:
  #12981
  https://devdiv.visualstudio.com/DevDiv/_git/WebTools/pullrequest/725194
  https://devdiv.visualstudio.com/DevDiv/_git/WebTools/pullrequest/725955

Add editor context menu commands for Razor nested files alongside the existing Solution Explorer commands. Uses VSCT CommandPlacements to share CSS/JS command IDs across both menus, and
IVsMonitorSelection.GetCurrentSelection to resolve the active file (which tracks the active window frame, not just Solution Explorer tree selection).

Key changes:

 - Unified NestedFileCommandHandler serves both Solution Explorer and editor menus via shared command IDs and SelectionHelper for selection/UIContext queries
 - Added editor context menu group (grpidRazorNestedFilesEditor) on IDM_VS_CTXT_CODEWIN with CSS/JS commands placed via CommandPlacements
 - For .cs in editor: intercept standard ViewCode (F7) command via UsedCommands so the F7 keybinding indicator displays automatically. Handler yields (Supported=false) to fall through to default ViewCode
when not in a Razor file
 - Added separate cmdidAddNestedCsFileEditor for the "Add .cs" case in editor, so it appears without the F7 keybinding when the .cs file doesn't exist
 - Added "View Page" command for navigating from nested files back to the parent Razor file, placed in editor, Solution Explorer, and CSS editor context menus
 - Extended UIContextRule to activate for nested files (.razor.* and .cshtml.*) in addition to .razor and .cshtml
 - ViewCodeCommandHandler (MEF F7 handler): returns Unavailable when .cs doesn't exist, excludes _Imports.razor and _ViewImports.cshtml, uses FileExistsHelper cache for per-keystroke performance
 - Added View_Page resource with translations, cleaned up unused Add_Code resource
 - Updated tests for new constructor signature and behavior
@ToddGrun ToddGrun requested a review from a team as a code owner April 8, 2026 20:50
Copy link
Copy Markdown
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some screenshots would be good, as we might be able to use them in release notes etc

NestedFileKind fileKind,
Lazy<LSPRequestInvokerWrapper> requestInvoker)
Lazy<LSPRequestInvokerWrapper> requestInvoker,
bool allowExternalHandlers = false,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not: I'd prefer to avoid optional parameters on internal code if it's not a big pain

@ToddGrun
Copy link
Copy Markdown
Contributor Author

ToddGrun commented Apr 9, 2026

Some screenshots would be good, as we might be able to use them in release notes etc

image
image

@ToddGrun ToddGrun merged commit c39bfd8 into main Apr 9, 2026
10 checks passed
@ToddGrun ToddGrun deleted the dev/toddgrun/nested_file_menu_support_in_editor branch April 9, 2026 03:52
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 9, 2026
@davidwengier davidwengier added the feature request Large improvement request label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Large improvement request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants