feat(services): show the debugger of a service in the Services tool window (#4803)

Debugging from Services showed only the console in the detail pane and the first breakpoint switched to the Debug tool window. The detail pane of a configuration being debugged now shows the whole debugger for that session (an attached run's console stays its Console tab), and a session started in place from Services reveals Services on a stop and reruns in place.
This commit is contained in:
l0ng-ai
2026-11-20 20:01:08 +08:00
committed by GitHub
parent b89febd61f
commit dd6d83fd2c
9 changed files with 86 additions and 19 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -23,7 +23,7 @@ description: "在服务工具窗口中管理运行配置、Docker 容器、镜
- 配置操作:**运行**(或 **重新运行**)、**调试**、**停止**、**在浏览器中打开**、**更新应用**(仅支持的配置)。
- 右键菜单:**在运行工具窗口中显示**、**在调试工具窗口中显示**、**编辑配置…**、**从服务中移除**。
运行过的配置会在详情区显示其控制台。在同一分组内可以拖动或用 **上移** / **下移** 调整顺序,顺序按项目保存。
运行过的配置会在详情区显示其控制台;从这里调试的配置在详情区显示完整的调试器(线程和变量、控制台、内存),命中断点时停留在服务工具窗口。在同一分组内可以拖动或用 **上移** / **下移** 调整顺序,顺序按项目保存。
## Docker
@@ -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> = [];
+2 -1
View File
@@ -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(),
+11 -6
View File
@@ -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
}
@@ -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;
}
+30 -2
View File
@@ -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 (
<div className={styles.serviceView} onPointerDownCapture={reselect} onFocusCapture={reselect}>
{shown && <DebugView consolePane={consolePane} />}
</div>
);
}
export function DebugToolWindow() {
return <DebugView />;
}
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" ? (
<NetworkView key={active.id} session={active.id} />
) : (
<DebugConsole key={active.id} session={active} />
(consolePane ?? <DebugConsole key={active.id} session={active} />)
)}
</div>
</div>
+8 -5
View File
@@ -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 <SessionPanel key={execution.run!.id} session={execution.run!} showLifecycle={false} />;
}
const execution = r.session?.run;
const runConsole = execution && <SessionPanel key={execution.id} session={execution} showLifecycle={false} />;
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 <View key={d.id} sessionId={d.id} console={runConsole} />;
if (runConsole) return runConsole;
if (d && Console)
return (
<div className={styles.debugConsole}>
+3 -1
View File
@@ -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.