Panel polish + editor context menu (Explain / Add to Chat) - #24
Panel polish + editor context menu (Explain / Add to Chat)#24DaveTseng2019 wants to merge 7 commits into
Conversation
Replace hardcoded FontSize values in the panel and compose dialog with bindings relative to VsFonts.EnvironmentFontSizeKey, so text follows the user's Tools > Options > Environment > Fonts and Colors setting live instead of staying fixed regardless of DPI/accessibility preferences. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The tool window's own Caption already shows "Claude Code" in the tab, so the panel's own header duplicated it. The Launch/External console buttons also got clipped instead of wrapping when the panel was docked narrower than they fit, unlike the checkbox row below them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Right-click in the code editor for two commands that reuse the existing at_mentioned/attachment plumbing: Explain stages the selection as a text attachment with an instruction header, Add to Chat @-mentions the file with the selection's line range. Both insert-not-submit, matching every other at_mentioned use in this codebase. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an editor context-menu entry point for “Claude Actions” (Explain / Add to Chat) and polishes the tool window UI so it behaves better at narrow widths and scales with Visual Studio’s Environment Font size.
Changes:
- Adds a code-editor context menu submenu (“Claude Actions”) with commands wired in the package to stage an Explain prompt or
at_mentionedthe current selection. - Updates the panel layout (wrap toolbar buttons, remove duplicate title) and introduces font-size scaling based on
VsFonts.EnvironmentFontSizeKey. - Documents VSCT and Exp-hive gotchas in
CLAUDE.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ClaudeCodeVS/VSCommandTable.vsct | Adds the “Claude Actions” context submenu and the Explain/Add to Chat command IDs. |
| src/ClaudeCodeVS/Ui/FontScale.cs | New helper to bind WPF FontSize to VS environment font size and scale descendants. |
| src/ClaudeCodeVS/Ui/ComposeDialog.cs | Binds dialog font sizing to VS environment settings; scales footer estimate text. |
| src/ClaudeCodeVS/Ui/ClaudeToolWindowControl.cs | Removes duplicate title, wraps toolbar buttons, and applies FontScale-based sizing. |
| src/ClaudeCodeVS/Editor/SelectionService.cs | Exposes the current selection and adds MentionCurrentAsync() for Add to Chat. |
| src/ClaudeCodeVS/ClaudeCodeVsPackage.cs | Registers commands and implements Explain/Add to Chat handlers. |
| CLAUDE.md | Adds notes about VSCT parenting and Exp hive command-table caching behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var @params = new JObject { ["filePath"] = info.FilePath }; | ||
| if (!info.IsEmpty) | ||
| { | ||
| @params["lineStart"] = info.StartLine; | ||
| @params["lineEnd"] = info.EndLine; | ||
| } |
| ErrorHandler.ThrowOnFailure(frame.Show()); | ||
| } | ||
|
|
||
| // Editor right-click ("Claude Action" submenu): Explain stages the selection as a text attachment |
| // One flat WrapPanel for all four buttons (no DockPanel right-docking): docking Clear/Output to | ||
| // the right pre-claims width, which clipped the Launch buttons mid-text at narrow panel widths. | ||
| // Wrapping keeps every button whole and reachable at any width; right-alignment wasn't worth that. | ||
| var toolbar = new WrapPanel { Margin = new Thickness(0, 0, 0, 8) }; |
- MentionCurrentAsync now sends a workspace-relative path (via the shared AttachmentService.ToWorkspaceRelative), matching the AttachmentService convention instead of leaking an absolute path. - Fix "Claude Action" -> "Claude Actions" comment to match the VSCT submenu text. - Remove the redundant toolbar.Margin set-then-override in ClaudeToolWindowControl. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
已依 Copilot review 的三點建議修正並推上新 commit (0b83d2b):
Release build 通過,其餘 warning 皆為既有、與本次改動無關。 |
Repeated clicks on "Launch Claude Code" each spawned a brand-new terminal/CLI process with no check for an already-connected session. Guard LaunchClaudeAsync behind server.HasConnections; the "hooks & tools didn't load" banner's Relaunch button gets its own RelaunchAction that bypasses the guard, since that flow deliberately re-pins a misconfigured (but already connected) session. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
追加一個修正(commit aaa271b): Bug:面板上「Launch Claude Code」按鈕沒有檢查是否已經有連線,每按一次都會多開一個 terminal + 修法: 但「Workspace hooks & tools didn't load for this session」警告卡片上的「Relaunch Claude Code」按鈕,語意是「目前這個連線設定錯了(沒 pin 到正確資料夾),要重開一個正確的」——這種情況下即使已連線也要允許重開。所以另外加了 實機驗證:連按兩次 Launch 只開一個 terminal(Activity log 出現 "already connected - not opening another terminal");workspace 未正確 pin 時的 Relaunch 按鈕邏輯已 code review 確認會 bypass guard(該情境需要巢狀 CLI 環境較難重現即時畫面,但程式邏輯簡單直接,風險低)。 |
The "hooks & tools didn't load" banner's Relaunch button promises to "pin the right folder," but if VS has no folder/workspace open there is no folder to pin - every relaunch just spawned another equally unpinned terminal that hit the same warning, inviting an endless click-relaunch-fail loop (reported after live testing). Refuse and tell the user to open a folder first instead of piling up dead terminals. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
追加第三個修正(commit 926921b),是上一個 duplicate-launch guard 修正之後在實機測試中發現的: Bug:"Workspace hooks & tools didn't load for this session" 警告卡片上的「Relaunch Claude Code」按鈕承諾「pins the right folder」,但如果 Visual Studio 本身根本沒開任何 folder/workspace,根本沒有「right folder」可以 pin。於是每次 relaunch 都只是再開一個一樣沒 pin 到正確目錄的 terminal,一樣觸發同一個警告,使用者只好再點一次 Relaunch——變成無限循環,一直開新視窗(實機測試重現)。 修法: 實機驗證:故意在沒開 workspace 的狀態下觸發連線、跳出警告卡片,點 Relaunch 確認不再多開視窗(process 數量沒變)。 |
|
@firish 這個 PR 目前累積了四個 commit(原本的面板整理/右鍵選單功能 + 依 Copilot review 修正 + 兩個額外發現的 Launch/Relaunch 重複開窗 bug 修正),都已經實機驗證過,麻煩有空看一下,謝謝! |
|
@DaveTseng2019 Thanks for the PR. I'm traveling over the next few days, but will review, test, and merge as soon as I am back. Appreciate you for taking the time to contribute! |
External console is a standalone window the user explicitly asks for each time, and upstream allows unlimited concurrent external consoles - only the docked Launch button should refuse to pile up redundant terminals.
|
Closing this on purpose - the work isn't abandoned. This PR accumulated several unrelated things (panel layout, editor context menu, and three launch/relaunch bug fixes found along the way), and its branch was cut from a local I'm splitting the same changes into smaller, self-contained PRs branched off a clean upstream |
Summary
@-mentions the file with the selection's line range) - both insert-not-submit, reusing the existing attachment/at_mentioned plumbing.Test plan
MSBuild /t:Build /p:Configuration=Release- clean build (pre-existing nullable warnings only).txtwith the correct header text, filename, and line range🤖 Generated with Claude Code