Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai d28bf8eeae 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.
2026-11-20 20:00:35 +08:00
l0ng-ai b89febd61f fix(debugger): quick-evaluate the whole method call under the mouse (#4801)
Quick Evaluate built the expression from the identifier and its member chain only, so on o.getX() it sent o.getX, which Java adapters resolve as a field, and it evaluated with the hover context, in which adapters refuse to call methods. Quick Evaluate and the Evaluate dialog seed now take the call of the clicked identifier and member chains through calls and indexing, and Quick Evaluate uses the watch context. Plain hovers and value-on-selection stay side-effect free.
2026-11-20 19:55:07 +08:00
13 змінених файлів з 187 додано та 27 видалено

No files matched your search

+1 -1
Переглянути файл
@@ -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
Переглянути файл
@@ -23,7 +23,7 @@ description: "在服务工具窗口中管理运行配置、Docker 容器、镜
- 配置操作:**运行**(或 **重新运行**)、**调试**、**停止**、**在浏览器中打开**、**更新应用**(仅支持的配置)。
- 右键菜单:**在运行工具窗口中显示**、**在调试工具窗口中显示**、**编辑配置…**、**从服务中移除**。
运行过的配置会在详情区显示其控制台。在同一分组内可以拖动或用 **上移** / **下移** 调整顺序,顺序按项目保存。
运行过的配置会在详情区显示其控制台;从这里调试的配置在详情区显示完整的调试器(线程和变量、控制台、内存),命中断点时停留在服务工具窗口。在同一分组内可以拖动或用 **上移** / **下移** 调整顺序,顺序按项目保存。
## Docker
+37
Переглянути файл
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { expressionAt } from "../editor/valueTooltip";
/** The expression around the `|` in `line`. */
function at(line: string, calls: boolean) {
const pos = line.indexOf("|");
const view = new EditorView({ state: EditorState.create({ doc: line.replace("|", "") }) });
const text = expressionAt(view, pos, { calls })?.text ?? null;
view.destroy();
return text;
}
describe("expression at the mouse for Quick Evaluate (#4772)", () => {
it("takes the call of the clicked method, arguments included", () => {
expect(at("String n = vo.getChd|rnum();", true)).toBe("vo.getChdrnum()");
expect(at('x = f|(a, g(b), "c)");', true)).toBe('f(a, g(b), "c)")');
expect(at("x = list.g|et (i);", true)).toBe("list.get (i)");
});
it("follows member chains through calls and indexing to the clicked member", () => {
expect(at("a.getB().c|()", true)).toBe("a.getB().c()");
expect(at("a.get|B().c()", true)).toBe("a.getB()");
expect(at("items[i + 1].na|me", true)).toBe("items[i + 1].name");
expect(at("a.b()[0].c|", true)).toBe("a.b()[0].c");
});
it("leaves an unbalanced call as the bare member", () => {
expect(at("vo.getChd|rnum(a,", true)).toBe("vo.getChdrnum");
});
it("keeps plain hovers free of calls", () => {
expect(at("String n = vo.getChd|rnum();", false)).toBe("vo.getChdrnum");
expect(at("a.getB().c|()", false)).toBe("c");
});
});
+3 -3
Переглянути файл
@@ -91,7 +91,7 @@ describe("paused editor evaluation", () => {
view.dispatch({ selection: { anchor: 0, head: 5 } });
expect(click().defaultPrevented).toBe(true);
await vi.waitFor(() => expect(document.querySelector(".cm-lsp-hint")?.textContent).toContain("order.items = 42"));
expect(ipc.debugEvaluateIn).toHaveBeenCalledExactlyOnceWith(7, 10, "order.items", "hover");
expect(ipc.debugEvaluateIn).toHaveBeenCalledExactlyOnceWith(7, 10, "order.items", "watch");
expect(view.state.selection.main.head).toBe(16);
});
@@ -101,7 +101,7 @@ describe("paused editor evaluation", () => {
session();
view.dispatch({ selection: { anchor: 0, head: doc.length } });
click();
await vi.waitFor(() => expect(ipc.debugEvaluateIn).toHaveBeenCalledWith(7, 10, doc, "hover"));
await vi.waitFor(() => expect(ipc.debugEvaluateIn).toHaveBeenCalledWith(7, 10, doc, "watch"));
expect(view.state.selection.main.from).toBe(0);
expect(view.state.selection.main.to).toBe(doc.length);
await vi.waitFor(() =>
@@ -114,7 +114,7 @@ describe("paused editor evaluation", () => {
const text = "(total +\n order.items)";
view.dispatch({ changes: { from: 0, to: doc.length, insert: text }, selection: { anchor: 0, head: text.length } });
click();
await vi.waitFor(() => expect(ipc.debugEvaluateIn).toHaveBeenCalledWith(7, 10, text, "hover"));
await vi.waitFor(() => expect(ipc.debugEvaluateIn).toHaveBeenCalledWith(7, 10, text, "watch"));
});
it("ignores an object response that arrives after the debugger resumes", async () => {
+18 -2
Переглянути файл
@@ -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> = [];
+3 -2
Переглянути файл
@@ -208,7 +208,7 @@ function evaluateSeed(view: EditorView | undefined = activeEditor()?.view, pos?:
const { state } = view;
const sel = state.selection.main;
if (!sel.empty && (pos == null || (sel.from <= pos && pos <= sel.to))) return state.sliceDoc(sel.from, sel.to);
return expressionAt(view, pos ?? sel.head)?.text ?? "";
return expressionAt(view, pos ?? sel.head, { calls: true })?.text ?? "";
}
async function quickEvaluate(arg?: unknown) {
@@ -234,7 +234,8 @@ async function quickEvaluate(arg?: unknown) {
);
};
try {
const value = await evaluate(expression, "hover", session);
// Unlike a plain hover, an explicit Quick Evaluate may call methods (adapters refuse that for "hover").
const value = await evaluate(expression, "watch", session);
if (session && stillCurrent()) showQuickValue(view, pos, expression, value, session.id);
} catch (e) {
if (stillCurrent()) showHint(view, e instanceof Error ? e.message : String(e), { pos, tone: "error" });
+58 -3
Переглянути файл
@@ -19,8 +19,45 @@ import styles from "./editor.module.css";
const BASE_HOVER = 100;
const IDENT = /[\p{L}\p{N}_$]/u;
/** Identifier (with `a.b.c` member access) around `pos`, or the selection containing it. */
export function expressionAt(view: EditorView, pos: number): { from: number; to: number; text: string } | null {
const OPEN: Record<string, string> = { ")": "(", "]": "[" };
const CLOSE: Record<string, string> = { "(": ")", "[": "]" };
/** Index just past the bracket group opening at `i` (strings skipped), or -1 when it doesn't close on the line. */
function closeOf(t: string, i: number): number {
const stack: string[] = [];
for (let j = i; j < t.length; j++) {
const c = t[j]!;
if (c === '"' || c === "'" || c === "`") {
j++;
while (j < t.length && t[j] !== c) j += t[j] === "\\" ? 2 : 1;
if (j >= t.length) return -1;
} else if (CLOSE[c]) stack.push(CLOSE[c]);
else if (c === ")" || c === "]") {
if (stack.pop() !== c) return -1;
if (!stack.length) return j + 1;
}
}
return -1;
}
/** Index of the bracket opening the group that closes at `i - 1`, or -1. */
function openOf(t: string, i: number): number {
for (let start = i - 1; start >= 0; start--) {
if (t[start] === OPEN[t[i - 1]!] && closeOf(t, start) === i) return start;
}
return -1;
}
/**
* Identifier (with `a.b.c` member access) around `pos`, or the selection containing it. With
* `calls`, as for Quick Evaluate: member chains through calls and indexing (`a.getB().c`,
* `items[i].name`) and the call of the identifier itself (`o.getX()`, `f(a, b)`).
*/
export function expressionAt(
view: EditorView,
pos: number,
{ calls = false } = {},
): { from: number; to: number; text: string } | null {
const { state } = view;
const sel = state.selection.main;
if (!sel.empty && pos >= sel.from && pos <= sel.to) {
@@ -33,7 +70,25 @@ export function expressionAt(view: EditorView, pos: number): { from: number; to:
let end = start;
if (!IDENT.test(t[end] ?? "") && !IDENT.test(t[start - 1] ?? "")) return null;
while (end < t.length && IDENT.test(t[end]!)) end++;
while (start > 0 && (IDENT.test(t[start - 1]!) || (t[start - 1] === "." && IDENT.test(t[start - 2] ?? "")))) start--;
for (;;) {
while (start > 0 && IDENT.test(t[start - 1]!)) start--;
if (t[start - 1] === "." && IDENT.test(t[start - 2] ?? "")) start--;
else if (calls && t[start - 1] === "." && OPEN[t[start - 2] ?? ""]) {
let open = openOf(t, start - 1);
// `a.b()[0].c`: walk back over every group, then the name they follow.
while (open > 0 && OPEN[t[open - 1]!]) open = openOf(t, open);
if (open <= 0 || !IDENT.test(t[open - 1]!)) break;
start = open;
} else break;
}
if (calls) {
let next = end;
while (t[next] === " ") next++;
if (t[next] === "(") {
const close = closeOf(t, next);
if (close > 0) end = close;
}
}
const text = t.slice(start, end);
if (!text || /^\d/.test(text)) return null;
return { from: line.from + start, to: line.from + end, text };
+2 -1
Переглянути файл
@@ -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
Переглянути файл
@@ -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
}
+12
Переглянути файл
@@ -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
Переглянути файл
@@ -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
Переглянути файл
@@ -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
Переглянути файл
@@ -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.