From d28bf8eeaeee9639ab4461ecd06cf5acc3a96d46 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 20 Nov 2026 20:00:35 +0800 Subject: [PATCH] feat(services): show the debugger of a service in the Services tool window Debugging a configuration from Services showed only its console in the detail pane, and the first breakpoint switched to the Debug tool window, taking the service list out of sight. The detail pane of a configuration being debugged now shows the whole debugger (toolbar, Threads & Variables, Console, Memory) for that session; the console of a run the debugger is attached to stays its Console tab. A session started in place from Services reveals Services on a stop and reruns in place; sessions started elsewhere still reveal the Debug tool window. --- docs/en/guide/services.mdx | 2 +- docs/zh/guide/services.mdx | 2 +- .../__tests__/startupBreakpoints.test.ts | 20 ++++++++++-- src/features/debugger/index.ts | 3 +- src/features/debugger/state.ts | 17 ++++++---- .../debugger/ui/DebugToolWindow.module.css | 12 +++++++ src/features/debugger/ui/DebugToolWindow.tsx | 32 +++++++++++++++++-- src/features/run/services.tsx | 13 +++++--- src/workbench/contributions.ts | 4 ++- 9 files changed, 86 insertions(+), 19 deletions(-) diff --git a/docs/en/guide/services.mdx b/docs/en/guide/services.mdx index 6d0730bba0..3b9ad7573c 100644 --- a/docs/en/guide/services.mdx +++ b/docs/en/guide/services.mdx @@ -23,7 +23,7 @@ Only types you add appear here: choose **Add Service › Run Configuration Type* - Configuration actions: **Run** (or **Rerun**), **Debug**, **Stop**, **Open in Browser**, **Update Application** (for configurations that support it). - Context menu: **Show in Run Tool Window**, **Show in Debug Tool Window**, **Edit Configuration…**, **Remove from Services**. -A configuration that ran shows its console in the detail pane. Reorder configurations within a group by dragging them or with **Move Up** / **Move Down**; the order is saved per project. +A configuration that ran shows its console in the detail pane; one debugged from here shows the whole debugger there (Threads & Variables, Console, Memory), and a breakpoint keeps the Services tool window in front. Reorder configurations within a group by dragging them or with **Move Up** / **Move Down**; the order is saved per project. ## Docker diff --git a/docs/zh/guide/services.mdx b/docs/zh/guide/services.mdx index be3ef0670a..3c78ceb413 100644 --- a/docs/zh/guide/services.mdx +++ b/docs/zh/guide/services.mdx @@ -23,7 +23,7 @@ description: "在服务工具窗口中管理运行配置、Docker 容器、镜 - 配置操作:**运行**(或 **重新运行**)、**调试**、**停止**、**在浏览器中打开**、**更新应用**(仅支持的配置)。 - 右键菜单:**在运行工具窗口中显示**、**在调试工具窗口中显示**、**编辑配置…**、**从服务中移除**。 -运行过的配置会在详情区显示其控制台。在同一分组内可以拖动或用 **上移** / **下移** 调整顺序,顺序按项目保存。 +运行过的配置会在详情区显示其控制台;从这里调试的配置在详情区显示完整的调试器(线程和变量、控制台、内存),命中断点时停留在服务工具窗口。在同一分组内可以拖动或用 **上移** / **下移** 调整顺序,顺序按项目保存。 ## Docker diff --git a/src/features/debugger/__tests__/startupBreakpoints.test.ts b/src/features/debugger/__tests__/startupBreakpoints.test.ts index 4d0b891024..6a157a5de7 100644 --- a/src/features/debugger/__tests__/startupBreakpoints.test.ts +++ b/src/features/debugger/__tests__/startupBreakpoints.test.ts @@ -70,19 +70,35 @@ it.each([undefined, true, false])( ); it.each(["breakpoint", "function breakpoint", "exception", "pause"])( - "reveals an in-place session on suspend (%s)", + "reveals an in-place session in Services on suspend (%s)", async (reason) => { const show = vi.fn(); provideToolWindowService({ show } as unknown as ToolWindowService); await startSession(config("launch"), { show: false }); expect(show).not.toHaveBeenCalled(); handleDebugEvent(42, { kind: "stopped", threadId: 1, reason, description: null, allThreadsStopped: true }); - expect(show).toHaveBeenCalledWith("debug"); + // Services shows the session's debugger in place (#4773). + expect(show).toHaveBeenCalledExactlyOnceWith("services"); expect(useDebug.getState().active).toBe(42); expect(useDebug.getState().sessions[42]).toMatchObject({ status: "paused", selectedThread: 1 }); }, ); +it("reveals a session started elsewhere in the Debug tool window on suspend", async () => { + const show = vi.fn(); + provideToolWindowService({ show } as unknown as ToolWindowService); + await startSession(config("launch")); + show.mockClear(); + handleDebugEvent(42, { + kind: "stopped", + threadId: 1, + reason: "breakpoint", + description: null, + allThreadsStopped: true, + }); + expect(show).toHaveBeenCalledExactlyOnceWith("debug"); +}); + it.each(["launch", "attach"])("awaits every file before %s can send configurationDone", async (request) => { const completed: string[] = []; const release: Array<() => void> = []; diff --git a/src/features/debugger/index.ts b/src/features/debugger/index.ts index 49ef13a789..dd45cd681a 100644 --- a/src/features/debugger/index.ts +++ b/src/features/debugger/index.ts @@ -79,6 +79,7 @@ function useLiveSessionCount(): number | null { export function activate(): () => void { useDebugRunSessions.setState({ Console: lazyComponent(() => import("./ui/DebugConsole").then((m) => m.DebugServiceConsole)), + View: lazyComponent(() => import("./ui/DebugToolWindow").then((m) => m.DebugServiceView)), }); loadWatches(useProject.getState().project?.root ?? null); publishContext(); @@ -88,7 +89,7 @@ export function activate(): () => void { loadJsBreakpoints(useProject.getState().project?.root ?? null); loadResponseOverrides(useProject.getState().project?.root ?? null); const disposers = [ - () => useDebugRunSessions.setState({ sessions: [], serviceSessions: [], Console: null }), + () => useDebugRunSessions.setState({ sessions: [], serviceSessions: [], Console: null, View: null }), registerDebugActions(), registerDebugTabActions(), registerDevToolsWindows(), diff --git a/src/features/debugger/state.ts b/src/features/debugger/state.ts index a02bfbf3ca..b2c9c28001 100644 --- a/src/features/debugger/state.ts +++ b/src/features/debugger/state.ts @@ -29,6 +29,7 @@ import { maybeEditorService, notifications, runOutput, + SERVICES_WINDOW, toolWindowService, useDebugRunSessions, } from "@/workbench/contributions"; @@ -77,6 +78,8 @@ export interface DebugSession { process: RunId | null; /** Pinned tab (root sessions): once finished, a later session opens a new tab instead of taking its place. */ pinned?: boolean; + /** Started in place from the Services tool window (root sessions): its stops show it there, not in the Debug window. */ + inPlace?: boolean; status: SessionStatus; stoppedThread: number | null; stopReason: string | null; @@ -720,6 +723,7 @@ export async function startPreparedSession( adapter: config.debugAdapter ?? "", runConfig: config, pinned, + inPlace: options.show === false, }), }, console: { ...s.console, [id]: [] }, @@ -821,6 +825,7 @@ export async function startSession( launch: options.rerunnable === false ? null : launch, process: options.process ?? null, pinned: preparation ? preparation.pinned : pinned, + inPlace: options.show === false, status: cur.status === "starting" ? "running" : cur.status, }, }, @@ -984,13 +989,12 @@ export async function rerunSession(id: DebugSessionId, options: { show?: boolean if (!root.runConfig && !launch) return; if (isLive(root)) await stopSession(root.id); rerunOf = root.id; + // A session debugged in place from Services reruns there too. + const show = options.show ?? (root.inPlace ? false : undefined); try { if (root.runConfig) - await executeAction( - "run.debugConfig", - options.show === false ? { config: root.runConfig, show: false } : root.runConfig, - ); - else await startSession(launch!, { show: options.show }); + await executeAction("run.debugConfig", show === false ? { config: root.runConfig, show: false } : root.runConfig); + else await startSession(launch!, { show }); } finally { rerunOf = null; } @@ -1364,7 +1368,8 @@ export function handleDebugEvent(id: DebugSessionId, event: DebugEvent) { void loadFrames(id, event.threadId, !markTraceStop(id, event.threadId, s.stops + 1)); const dbg = workflowSettings().debugger; try { - if (dbg.showOnBreakpoint) toolWindowService().show("debug"); + // A session debugged in place from Services shows its debugger there (#4773). + if (dbg.showOnBreakpoint) toolWindowService().show(rootOf(s).inPlace ? SERVICES_WINDOW : "debug"); } catch { // ignore } diff --git a/src/features/debugger/ui/DebugToolWindow.module.css b/src/features/debugger/ui/DebugToolWindow.module.css index fdaaed22a0..21bc68ad13 100644 --- a/src/features/debugger/ui/DebugToolWindow.module.css +++ b/src/features/debugger/ui/DebugToolWindow.module.css @@ -353,3 +353,15 @@ border-bottom: 0; border-top: 1px solid var(--border); } + +.serviceView { + display: flex; + flex-direction: column; + height: 100%; + min-height: 0; +} + +.serviceView > * { + flex: 1; + min-height: 0; +} diff --git a/src/features/debugger/ui/DebugToolWindow.tsx b/src/features/debugger/ui/DebugToolWindow.tsx index 1b1a570a51..14cc65e24a 100644 --- a/src/features/debugger/ui/DebugToolWindow.tsx +++ b/src/features/debugger/ui/DebugToolWindow.tsx @@ -1,6 +1,6 @@ /** Debug tool window: toolbar, Threads & Variables (frames + variables), Console. */ import { writeClipboardText } from "@/platform/clipboard"; -import { useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent } from "react"; +import { useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import clsx from "clsx"; import { executeAction } from "@/platform/actions"; import { basename, useProject } from "@/platform/project"; @@ -173,7 +173,35 @@ export function DebugTabs() { ); } +/** + * Services › a configuration being debugged: the same debugger as the Debug tool window, for + * that session (#4773). `console` replaces the Console tab, e.g. with the console of the run the + * debugger is attached to. + */ +export function DebugServiceView({ sessionId, console: consolePane }: { sessionId: number; console?: ReactNode }) { + const shown = useDebug((s) => { + const active = s.active != null ? s.sessions[s.active] : undefined; + return !!active && rootOf(active).id === sessionId; + }); + useEffect(() => { + if (useDebug.getState().sessions[sessionId]) selectSession(sessionId); + }, [sessionId]); + // The toolbar acts on the active session: using this view makes its session the active one again. + const reselect = () => { + if (!shown && useDebug.getState().sessions[sessionId]) selectSession(sessionId); + }; + return ( +