feat(debugger): Remove All Watches in the Variables view's context menu (#4647)

A watch row's context menu in the Variables view gets Remove All Watches next to Remove Watch; it empties the project's stored watch list. Verified with debugger and locale vitest and typecheck; main merged in (locale conflict resolved).

Co-authored-by: mansur-akhmadi <10739460+mansur-akhmadi@users.noreply.github.com>
This commit is contained in:
Mansur Akhmadi
2026-11-20 10:15:56 +08:00
committed by GitHub
co-authored by mansur-akhmadi
parent 36ecb53159
commit 3dd5c75fa0
8 changed files with 69 additions and 7 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ These commands are in the **Run** menu and on the Debug tool window toolbar.
While the program is suspended:
- The **Variables** view shows the variables of the selected frame. Right-click a value for **Set Value…** (`F2`), **Copy Value**, **Copy Name**, **Jump to Source** (`F4`) and **Add to Watches**.
- **Watches** appear at the top of the Variables view and are re-evaluated on every stop and frame change. Add one with **Add to Watches**; remove it with **Remove Watch**.
- **Watches** appear at the top of the Variables view and are re-evaluated on every stop and frame change. Add one with **Add to Watches**; remove it with **Remove Watch**, or all of them with **Remove All Watches**.
- Hovering a variable in the editor shows its value. `⌥`-click (`Alt`-click) or **Quick Evaluate Expression** (`⌘⌥F8` / `Ctrl+Alt+F8`) evaluates the expression under the mouse or the selection.
- Values of local variables are shown inline after the lines that use them.
- **Evaluate Expression…** (`⌥F8` / `Alt+F8`) opens a dialog that evaluates any expression in the selected frame, keeps a history, and can add the expression to watches.
+1 -1
View File
@@ -125,7 +125,7 @@ C 和 C++ 的配置也可以改用 GDB 14 及以上版本(`gdb -i dap`):
程序挂起时:
- **变量** 视图显示选中帧的变量。右键点击某个值,可以 **设置值…**(`F2`)、**复制值**、**复制名称**、**跳转到源代码**(`F4`)和 **添加到监视**。
- 监视表达式显示在变量视图顶部,每次停下或切换帧时重新计算。用 **添加到监视** 添加,用 **移除监视** 删除。
- 监视表达式显示在变量视图顶部,每次停下或切换帧时重新计算。用 **添加到监视** 添加,用 **移除监视** 删除,用 **移除所有监视** 一次全部删除。
- 在编辑器里悬停变量会显示它的值。`⌥` 点击(`Alt` 点击)或 **快速计算表达式**(`⌘⌥F8` / `Ctrl+Alt+F8`)计算鼠标下的表达式或选中的内容。
- 局部变量的值会内联显示在使用它们的行尾。
- **计算表达式…**(`⌥F8` / `Alt+F8`)打开对话框,在选中帧里计算任意表达式,带历史记录,也能把表达式加入监视。
@@ -396,6 +396,32 @@ describe("variables the adapter computes after the stop", () => {
}
});
it("offers Remove All Watches on a watch's context menu", 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] : []));
};
try {
setup();
await screen.findByText("label.upper()");
await screen.findByText("'hi'");
expect(menu("label").map((i) => i.label)).not.toContain("Remove All Watches");
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(removeAll).toBeTruthy();
act(() => (removeAll as { run: () => void }).run());
expect(useDebug.getState().watches).toEqual([]);
await waitFor(() => expect(screen.queryByText("label.upper()")).toBeNull());
expect(screen.getByText("'hi'")).toBeTruthy();
} finally {
useDebug.setState({ watches: [] });
}
});
it("reloads after Set Value", async () => {
setup();
await screen.findByText("Collecting data…");
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from "vitest";
import { addWatch, loadWatches, useDebug } from "../state";
import { addWatch, loadWatches, removeAllWatches, useDebug } from "../state";
const SHARED = "openidea.debugger.watches";
const of = (root: string) => `${SHARED}:${root}`;
@@ -41,6 +41,23 @@ describe("watch storage", () => {
expect(watches()).toEqual([]);
});
it("Remove All Watches empties the project's stored list", () => {
localStorage.setItem(SHARED, '["legacy"]');
loadWatches("/a");
addWatch("x");
addWatch("y");
loadWatches("/b");
addWatch("z");
loadWatches("/a");
removeAllWatches();
expect(watches()).toEqual([]);
expect(localStorage.getItem(of("/a"))).toBe("[]");
loadWatches("/a");
expect(watches()).toEqual([]);
loadWatches("/b");
expect(watches()).toEqual(["legacy", "z"]);
});
it("without a project nothing is stored", () => {
loadWatches(null);
addWatch("z");
+5
View File
@@ -1221,6 +1221,11 @@ export function removeWatch(expression: string) {
persistWatches();
}
export function removeAllWatches() {
useDebug.setState({ watches: [] });
persistWatches();
}
/** Watches used to be one list for every project; it is only read now, as a project's first list. */
const SHARED_WATCH_KEY = "openidea.debugger.watches";
const watchKey = (root: string) => `${SHARED_WATCH_KEY}:${root}`;
+14 -2
View File
@@ -9,7 +9,15 @@ import { activeEditor } from "@/editor/api";
import { notifications } from "@/workbench/contributions";
import { addFieldWatchpoint } from "../breakpoints/special";
import { methodAt } from "../breakpoints/symbols";
import { activeSession, addWatch, removeWatch, revealFrame, sessionSupports, setVariableValue } from "../state";
import {
activeSession,
addWatch,
removeAllWatches,
removeWatch,
revealFrame,
sessionSupports,
setVariableValue,
} from "../state";
import { blurDebugView, focusDebugView } from "./focusedView";
import { classifyValue, oneLine, shownValue, sortVariables } from "../values";
import { valueText } from "../valueText";
@@ -300,7 +308,11 @@ export function VariablesView({
{ 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) });
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) });
+2 -1
View File
@@ -2706,5 +2706,6 @@
"<schema>": "<schema>",
"Shelve Silently": "Shelve Silently",
"Unshelve Silently": "Unshelve Silently",
"Fold Lines Like This": "Fold Lines Like This"
"Fold Lines Like This": "Fold Lines Like This",
"Remove All Watches": "Remove All Watches"
}
+2 -1
View File
@@ -9073,5 +9073,6 @@
"Resize shelf panes": "调整搁置记录和文件窗格大小",
"Database and schema": "数据库和 schema",
"Shelve Silently": "静默搁置",
"Unshelve Silently": "静默取消搁置"
"Unshelve Silently": "静默取消搁置",
"Remove All Watches": "移除所有监视"
}