From 6b2b4a96e776e5c052d9e9922b38cf465ab7e70b Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 14:33:37 +0800 Subject: [PATCH] fix(debugger): align the thread selector with the frames pane (#4961) - Give the thread selector the width of the call stack header, with the standard workbench font and a fixed chevron at the trailing edge. - Show a leading icon for running, suspended, and breakpoint threads in both the header and the menu. Keep the status text in the menu and make the selected thread's full name and status available in the header tooltip and accessible description. --- e2e/debugThreadLayout.spec.ts | 66 +++++++++++++++++++ .../debugger/ui/DebugToolWindow.module.css | 5 +- src/features/debugger/ui/DebugToolWindow.tsx | 50 +++++++++----- src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + src/ui/Select.tsx | 5 ++ src/ui/icons.tsx | 3 + src/ui/openidea/debugger/threadBreakpoint.svg | 4 ++ src/ui/openidea/debugger/threadRunning.svg | 4 ++ src/ui/openidea/debugger/threadSuspended.svg | 4 ++ 10 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 e2e/debugThreadLayout.spec.ts create mode 100644 src/ui/openidea/debugger/threadBreakpoint.svg create mode 100644 src/ui/openidea/debugger/threadRunning.svg create mode 100644 src/ui/openidea/debugger/threadSuspended.svg diff --git a/e2e/debugThreadLayout.spec.ts b/e2e/debugThreadLayout.spec.ts new file mode 100644 index 000000000..14410adb4 --- /dev/null +++ b/e2e/debugThreadLayout.spec.ts @@ -0,0 +1,66 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("shows thread states in the compact frames header and switches frames by keyboard", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 940, height: 740 }); + await stubDesktop(page); + await page.evaluate(async () => { + const stateModule = "/src/features/debugger/state.ts"; + const workbenchModule = "/src/workbench/contributions.ts"; + const { adoptSession } = await import(/* @vite-ignore */ stateModule); + const { toolWindowService } = await import(/* @vite-ignore */ workbenchModule); + const frame = (id: number, name: string) => ({ + id, + name, + path: null, + line: 0, + column: 0, + presentationHint: null, + }); + const handlers = window.__ipc.handlers; + handlers.debug_stack_trace = ({ threadId }) => [frame(Number(threadId) * 10, "writeLedger")]; + handlers.debug_scopes = () => []; + adoptSession(97, { + name: "Settlement", + adapter: "debugpy", + status: "paused", + stoppedThread: 1, + selectedThread: 1, + stopReason: "breakpoint", + suspendedThreads: [{ id: 2, reason: "pause", description: null }], + threads: [ + { id: 1, name: "MainThread" }, + { id: 2, name: "Audit writer" }, + { id: 3, name: "Regional settlement reconciliation worker with a long queue name" }, + ], + selectedFrame: 10, + frames: [frame(10, "settle")], + }); + toolWindowService().show("debug", true); + }); + + const debug = page.getByRole("region", { name: "Debug", exact: true }); + const thread = debug.getByRole("button", { name: "Thread", exact: true }); + await expect(thread).toBeVisible(); + const remainder = await thread.evaluate((button) => button.parentElement!.clientWidth - button.clientWidth); + expect(remainder).toBeLessThan(12); + await expect(thread).toHaveAccessibleDescription("MainThread (At breakpoint)"); + const frames = debug.getByRole("listbox", { name: "Frames" }); + await expect(frames.getByText("settle", { exact: true })).toBeVisible(); + + await thread.press("ArrowDown"); + const menu = page.getByRole("listbox", { name: "Thread" }); + await expect(menu).toBeInViewport({ ratio: 1 }); + await expect(menu.getByRole("option", { name: "MainThread At breakpoint" })).toBeVisible(); + await expect(menu.getByRole("option", { name: "Audit writer Suspended" })).toBeVisible(); + await expect( + menu.getByRole("option", { name: /Regional settlement reconciliation worker .* Running/ }), + ).toBeVisible(); + await page.keyboard.press("ArrowDown"); + await page.keyboard.press("Enter"); + await expect(menu).toBeHidden(); + await expect(thread).toHaveAccessibleDescription("Audit writer (Suspended)"); + await expect(frames.getByText("writeLedger", { exact: true })).toBeVisible(); + expect(await ipcCalls(page, "debug_stack_trace")).toEqual([{ session: 97, threadId: 2 }]); +}); diff --git a/src/features/debugger/ui/DebugToolWindow.module.css b/src/features/debugger/ui/DebugToolWindow.module.css index 21bc68ad1..801a0d780 100644 --- a/src/features/debugger/ui/DebugToolWindow.module.css +++ b/src/features/debugger/ui/DebugToolWindow.module.css @@ -109,13 +109,14 @@ display: flex; align-items: center; flex: none; - height: 30px; + height: var(--h-field); padding: 0 var(--space-1); border-bottom: 1px solid var(--border); } .threadSelect { - max-width: 100%; + width: 100%; + font-size: var(--fs-ui); } .frameList { diff --git a/src/features/debugger/ui/DebugToolWindow.tsx b/src/features/debugger/ui/DebugToolWindow.tsx index e491c436b..52f793b0c 100644 --- a/src/features/debugger/ui/DebugToolWindow.tsx +++ b/src/features/debugger/ui/DebugToolWindow.tsx @@ -22,6 +22,7 @@ import { type TabItem, T, } from "@/ui"; +import type { SelectOption } from "@/ui/Select"; import { revealVertically } from "@/ui/Tabs"; import { setMuted, useBreakpoints } from "../breakpoints/store"; import { frameLabel, groupFrames } from "../frames"; @@ -374,6 +375,37 @@ function ThreadsAndVariables({ session }: { session: DebugSession }) { ); } +function ThreadSelector({ session }: { session: DebugSession }) { + const tr = useTx(); + const value = session.selectedThread == null ? null : String(session.selectedThread); + const options = session.threads.map(({ id, name }) => { + const option = { value: String(id), label: name, verbatim: true }; + if (!isLive(session)) return option; + if (!isThreadSuspended(session, id)) return { ...option, icon: "thread-running", detail: "Running" }; + const reason = + id === session.stoppedThread ? session.stopReason : session.suspendedThreads?.find((t) => t.id === id)?.reason; + return reason === "breakpoint" || reason?.endsWith(" breakpoint") + ? { ...option, icon: "thread-breakpoint", detail: "At breakpoint" } + : { ...option, icon: "thread-suspended", detail: "Suspended" }; + }); + const selected = options.find((option) => option.value === value); + const summary = selected?.detail ? `${selected.label} (${tr(selected.detail)})` : selected?.label; + return ( +
+ ({ - value: String(t.id), - label: t.name, - verbatim: true, - detail: isThreadSuspended(session, t.id) ? "suspended" : undefined, - }))} - onChange={(v) => void selectThread(session.id, +v)} - aria-label="Thread" - variant="ghost" - className={styles.threadSelect} - /> -
- )} + {session.threads.length > 0 && }
{ /** `ghost` renders as plain text + chevron (title bar widgets); `chip` as a chip that opens. */ variant?: "framed" | "ghost" | "chip"; className?: string; + title?: string; "aria-label"?: string; + "aria-description"?: string; /** Custom trigger content. */ renderValue?: (option: SelectOption | undefined) => ReactNode; /** Show a search box in the popup (useful for long option lists); typing on the closed trigger opens it with that text. */ @@ -324,6 +326,7 @@ export function Select({ disabled, variant = "framed", className, + title, renderValue, searchable = false, onPreview, @@ -355,6 +358,8 @@ export function Select({ aria-haspopup="listbox" aria-expanded={open} aria-label={given(aria["aria-label"])} + aria-description={aria["aria-description"]} + title={title} disabled={disabled} className={clsx(styles.trigger, styles[variant], className)} onClick={() => (open ? setOpen(false) : openPopup())} diff --git a/src/ui/icons.tsx b/src/ui/icons.tsx index 9eed09ca1..23e17f143 100644 --- a/src/ui/icons.tsx +++ b/src/ui/icons.tsx @@ -480,6 +480,9 @@ const ICONS = { "stop-filled": "run/stop_stroke", resume: "run/resume", pause: "run/pause", + "thread-running": "openidea/debugger/threadRunning", + "thread-suspended": "openidea/debugger/threadSuspended", + "thread-breakpoint": "openidea/debugger/threadBreakpoint", "step-over": "run/stepOver", "step-into": "run/stepInto", "step-out": "run/stepOut", diff --git a/src/ui/openidea/debugger/threadBreakpoint.svg b/src/ui/openidea/debugger/threadBreakpoint.svg new file mode 100644 index 000000000..62d7f2d13 --- /dev/null +++ b/src/ui/openidea/debugger/threadBreakpoint.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/ui/openidea/debugger/threadRunning.svg b/src/ui/openidea/debugger/threadRunning.svg new file mode 100644 index 000000000..1f28c5808 --- /dev/null +++ b/src/ui/openidea/debugger/threadRunning.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/ui/openidea/debugger/threadSuspended.svg b/src/ui/openidea/debugger/threadSuspended.svg new file mode 100644 index 000000000..0516d863b --- /dev/null +++ b/src/ui/openidea/debugger/threadSuspended.svg @@ -0,0 +1,4 @@ + + + +