Skip to content

Panel polish + editor context menu (Explain / Add to Chat) - #24

Closed
DaveTseng2019 wants to merge 7 commits into
firish:mainfrom
DaveTseng2019:fix/panel-title-and-button-wrap
Closed

Panel polish + editor context menu (Explain / Add to Chat)#24
DaveTseng2019 wants to merge 7 commits into
firish:mainfrom
DaveTseng2019:fix/panel-title-and-button-wrap

Conversation

@DaveTseng2019

Copy link
Copy Markdown

Summary

  • Editor right-click "Claude Actions" submenu with Explain (stages the selection as a text attachment with an instruction header) and Add to Chat (@-mentions the file with the selection's line range) - both insert-not-submit, reusing the existing attachment/at_mentioned plumbing.
  • Panel: removed the duplicate panel title and wrapped the toolbar buttons at narrow widths.
  • Panel fonts now scale with VS's Environment Font size.

Test plan

  • MSBuild /t:Build /p:Configuration=Release - clean build (pre-existing nullable warnings only)
  • Deployed to a disposable Exp hive; verified via DTE automation + screenshots:
    • Right-click in the code editor shows "Claude Actions" > Explain / Add to Chat
    • Explain stages a .txt with the correct header text, filename, and line range
    • Add to Chat raises no exception with/without a connected CLI session

🤖 Generated with Claude Code

DaveTseng2019 and others added 3 commits August 6, 2026 14:52
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>
Copilot AI lite review requested due to automatic review settings August 7, 2026 07:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_mentioned the 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.

Comment on lines +73 to +78
var @params = new JObject { ["filePath"] = info.FilePath };
if (!info.IsEmpty)
{
@params["lineStart"] = info.StartLine;
@params["lineEnd"] = info.EndLine;
}
Comment thread src/ClaudeCodeVS/ClaudeCodeVsPackage.cs Outdated
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>
@DaveTseng2019

Copy link
Copy Markdown
Author

已依 Copilot review 的三點建議修正並推上新 commit (0b83d2b):

  1. MentionCurrentAsync 改用共用的 AttachmentService.ToWorkspaceRelative 轉成 workspace-relative path,不再送出絕對路徑。
  2. 註解文字 "Claude Action" 改成 "Claude Actions",跟選單文字對齊。
  3. 移除 toolbar.Margin 先設值又立刻被覆蓋的多餘寫法。

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>
@DaveTseng2019

Copy link
Copy Markdown
Author

追加一個修正(commit aaa271b):

Bug:面板上「Launch Claude Code」按鈕沒有檢查是否已經有連線,每按一次都會多開一個 terminal + claude process,累積出一堆多餘的重複 session。

修法LaunchClaudeAsync 加上 _server.HasConnections guard,已連線時直接 no-op(log 一行提示),不再開新視窗。

但「Workspace hooks & tools didn't load for this session」警告卡片上的「Relaunch Claude Code」按鈕,語意是「目前這個連線設定錯了(沒 pin 到正確資料夾),要重開一個正確的」——這種情況下即使已連線也要允許重開。所以另外加了 BridgeStatus.RelaunchAction(帶 forceRelaunch: true)繞過這個 guard,兩個按鈕各自對應正確的語意。

實機驗證:連按兩次 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>
@DaveTseng2019

Copy link
Copy Markdown
Author

追加第三個修正(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——變成無限循環,一直開新視窗(實機測試重現)。

修法LaunchClaudeAsyncforceRelaunch=trueGetWorkspaceRootAsync() 拿不到 workspace 時直接拒絕、印出清楚的提示(先用 File > Open > Folder 開一個資料夾再 relaunch),不再盲目多開一個注定失敗的 terminal。

實機驗證:故意在沒開 workspace 的狀態下觸發連線、跳出警告卡片,點 Relaunch 確認不再多開視窗(process 數量沒變)。

@DaveTseng2019

Copy link
Copy Markdown
Author

@firish 這個 PR 目前累積了四個 commit(原本的面板整理/右鍵選單功能 + 依 Copilot review 修正 + 兩個額外發現的 Launch/Relaunch 重複開窗 bug 修正),都已經實機驗證過,麻煩有空看一下,謝謝!

@firish

firish commented Aug 7, 2026

Copy link
Copy Markdown
Owner

@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.
@DaveTseng2019

Copy link
Copy Markdown
Author

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 main that already carried #21's commit - so it lists 7 commits and overlaps #21. Reviewing it as one unit isn't fair to you.

I'm splitting the same changes into smaller, self-contained PRs branched off a clean upstream main and will resubmit shortly. Please don't spend review time on this one - thanks for the offer, and sorry for the churn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants