diff --git a/docs/en/guide/services.mdx b/docs/en/guide/services.mdx index 6d0730bba..3b9ad7573 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 be3ef0670..3c78ceb41 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 4d0b89102..6a157a5de 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 49ef13a78..dd45cd681 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 a02bfbf3c..b2c9c2800 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 fdaaed22a..21bc68ad1 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 1b1a570a5..14cc65e24 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 ( +
+ {shown && } +
+ ); +} + export function DebugToolWindow() { + return ; +} + +function DebugView({ consolePane }: { consolePane?: ReactNode }) { const tx = useTx(); const active = useDebug((s) => (s.active != null ? s.sessions[s.active] : undefined)); const muted = useBreakpoints((s) => s.muted); @@ -314,7 +342,7 @@ export function DebugToolWindow() { ) : tab === "network" ? ( ) : ( - + (consolePane ?? ) )} diff --git a/src/features/run/services.tsx b/src/features/run/services.tsx index 15c5b2bf1..e55d3f756 100644 --- a/src/features/run/services.tsx +++ b/src/features/run/services.tsx @@ -757,7 +757,7 @@ function RunDetail({ item }: { item: ServiceTreeItem }) { // Re-render on session changes. useRun((s) => s.sessions); const debugViews = useDebugRunSessions(); - const Console = debugViews.Console; + const { Console, View } = debugViews; const t = useT(); const txTemplate = useTxTemplate(); const r = resolve(item); @@ -773,11 +773,14 @@ function RunDetail({ item }: { item: ServiceTreeItem }) { ); // The configuration ran: its console, as in the Run tool window. Run / Debug / Stop // come from this window's toolbar (the selection), so the console strip leaves them out. - if (r.session?.run) { - const execution = r.session; - return ; - } + const execution = r.session?.run; + const runConsole = execution && ; const d = r.session?.debug[0]; + // Being debugged: the whole debugger in place, as in IDEA's Services (#4773); the console of a + // run the debugger is attached to stays its Console tab. + if (d && View && (d.status !== "terminated" || !execution)) + return ; + if (runConsole) return runConsole; if (d && Console) return (
diff --git a/src/workbench/contributions.ts b/src/workbench/contributions.ts index 1e1987047..d8e8108e4 100644 --- a/src/workbench/contributions.ts +++ b/src/workbench/contributions.ts @@ -1980,7 +1980,9 @@ export const useDebugRunSessions = create<{ sessions: DebugRunSession[]; serviceSessions: DebugServiceSession[]; Console: ComponentType<{ sessionId: number }> | null; -}>(() => ({ sessions: [], serviceSessions: [], Console: null })); + /** The whole debugger of a session (Services shows it in place); `console` replaces its Console tab. */ + View: ComponentType<{ sessionId: number; console?: ReactNode }> | null; +}>(() => ({ sessions: [], serviceSessions: [], Console: null, View: null })); /** * The Services tool window's badge: how many of its listed services are running.