mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(debugger): group variable and watch context menu actions (#5093)
The debugger variable menu groups Set Value with Copy Value and Copy Name, and watch creation and field watchpoints get their own group when available. The watch menu puts Remove Watch and Remove All Watches first, above value and source commands.
This commit is contained in:
@@ -348,10 +348,10 @@ describe("debug tool window", () => {
|
||||
|
||||
describe("variables the adapter computes after the stop", () => {
|
||||
const tick = () => act(() => new Promise((resolve) => setTimeout(resolve, 0)));
|
||||
const setup = () => {
|
||||
const setup = (current = session) => {
|
||||
adapterData.library = "Collecting data…";
|
||||
adapterData.scopes.mockClear();
|
||||
useDebug.setState({ sessions: { 1: session }, active: 1, stopSeq: 1, variablesEpoch: 0 });
|
||||
useDebug.setState({ sessions: { 1: current }, active: 1, stopSeq: 1, variablesEpoch: 0 });
|
||||
return render(<DebugToolWindow />);
|
||||
};
|
||||
|
||||
@@ -396,22 +396,42 @@ describe("variables the adapter computes after the stop", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("offers Remove All Watches on a watch's context menu", async () => {
|
||||
it("groups variable and watch context menu actions", async () => {
|
||||
useDebug.setState({ watches: ["count + 1", "label.upper()"] });
|
||||
const menu = (text: string) => {
|
||||
fireEvent.contextMenu(screen.getByText(text).closest("[role=treeitem]")!);
|
||||
const items = useContextMenuStore.getState().menu?.items ?? [];
|
||||
act(() => hideContextMenu());
|
||||
return items.flatMap((i) => ("label" in i && i.label ? [i] : []));
|
||||
return items;
|
||||
};
|
||||
const layout = (items: ReturnType<typeof menu>) =>
|
||||
items.map((item) => (item.kind === "separator" ? "|" : item.label));
|
||||
try {
|
||||
setup();
|
||||
setup({ ...session, caps: { dataBreakpoints: true } as DebugSession["caps"] });
|
||||
await screen.findByText("label.upper()");
|
||||
await screen.findByText("'hi'");
|
||||
expect(menu("label").map((i) => i.label)).not.toContain("Remove All Watches");
|
||||
expect(layout(menu("label"))).toEqual([
|
||||
"Set Value…",
|
||||
"Copy Value",
|
||||
"Copy Name",
|
||||
"|",
|
||||
"Add to Watches",
|
||||
"Add Field Watchpoint",
|
||||
"|",
|
||||
"Jump to Source",
|
||||
]);
|
||||
const items = menu("count + 1");
|
||||
expect(items.map((i) => i.label)).toContain("Remove Watch");
|
||||
const removeAll = items.find((i) => i.label === "Remove All Watches");
|
||||
expect(layout(items)).toEqual([
|
||||
"Remove Watch",
|
||||
"Remove All Watches",
|
||||
"|",
|
||||
"Set Value…",
|
||||
"Copy Value",
|
||||
"Copy Name",
|
||||
"|",
|
||||
"Jump to Source",
|
||||
]);
|
||||
const removeAll = items.find((i) => "label" in i && i.label === "Remove All Watches");
|
||||
expect(removeAll).toBeTruthy();
|
||||
act(() => (removeAll as { run: () => void }).run());
|
||||
expect(useDebug.getState().watches).toEqual([]);
|
||||
|
||||
@@ -390,36 +390,38 @@ export function VariablesView({
|
||||
};
|
||||
|
||||
const onContextMenu = (node: VarNode | null, _sel: Set<string>, e: React.MouseEvent) => {
|
||||
if (!node || node.kind === "message") return;
|
||||
if (!node || node.kind === "message" || node.kind === "scope") return;
|
||||
e.preventDefault();
|
||||
const items: MenuItem[] = [];
|
||||
if (editable(node))
|
||||
items.push(
|
||||
{ label: "Set Value…", icon: "edit", shortcut: "F2", run: () => startEdit(node) },
|
||||
{ kind: "separator" },
|
||||
);
|
||||
if (node.kind === "watch")
|
||||
items.push(
|
||||
{ label: "Remove Watch", icon: "minus", run: () => removeWatch(node.name) },
|
||||
{ label: "Remove All Watches", run: removeAllWatches },
|
||||
);
|
||||
if (node.kind !== "scope") {
|
||||
items.push({ label: "Copy Value", icon: "copy", run: () => void copyValue(node) });
|
||||
items.push({ label: "Copy Name", run: () => void writeClipboardText(node.name) });
|
||||
if (node.kind === "var" && node.evaluateName)
|
||||
items.push({ label: "Add to Watches", icon: "eye", run: () => addWatch(node.evaluateName!) });
|
||||
if (canWatch(node))
|
||||
items.push({
|
||||
label: "Add Field Watchpoint",
|
||||
icon: "breakpoint-field",
|
||||
run: () => void addWatchpointFor(session!, node),
|
||||
});
|
||||
items.push(
|
||||
{ kind: "separator" },
|
||||
{ label: "Jump to Source", shortcut: "F4", run: () => void jumpToDeclaration(node) },
|
||||
);
|
||||
}
|
||||
if (items.length) showContextMenu(e, items);
|
||||
if (editable(node)) items.push({ label: "Set Value…", icon: "edit", shortcut: "F2", run: () => startEdit(node) });
|
||||
items.push(
|
||||
{ label: "Copy Value", icon: "copy", run: () => void copyValue(node) },
|
||||
{ label: "Copy Name", run: () => void writeClipboardText(node.name) },
|
||||
);
|
||||
|
||||
const watchActions: MenuItem[] = [];
|
||||
const expression = node.evaluateName;
|
||||
if (node.kind === "var" && expression)
|
||||
watchActions.push({ label: "Add to Watches", icon: "eye", run: () => addWatch(expression) });
|
||||
if (canWatch(node))
|
||||
watchActions.push({
|
||||
label: "Add Field Watchpoint",
|
||||
icon: "breakpoint-field",
|
||||
run: () => void addWatchpointFor(session!, node),
|
||||
});
|
||||
if (watchActions.length) items.push({ kind: "separator" }, ...watchActions);
|
||||
|
||||
items.push(
|
||||
{ kind: "separator" },
|
||||
{ label: "Jump to Source", shortcut: "F4", run: () => void jumpToDeclaration(node) },
|
||||
);
|
||||
showContextMenu(e, items);
|
||||
};
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
|
||||
Reference in New Issue
Block a user