diff --git a/docs/en/guide/debugging.mdx b/docs/en/guide/debugging.mdx index 1bb96f1fd..371c73fdb 100644 --- a/docs/en/guide/debugging.mdx +++ b/docs/en/guide/debugging.mdx @@ -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. diff --git a/docs/zh/guide/debugging.mdx b/docs/zh/guide/debugging.mdx index bc1566e2f..cdae5193b 100644 --- a/docs/zh/guide/debugging.mdx +++ b/docs/zh/guide/debugging.mdx @@ -125,7 +125,7 @@ C 和 C++ 的配置也可以改用 GDB 14 及以上版本(`gdb -i dap`): 程序挂起时: - **变量** 视图显示选中帧的变量。右键点击某个值,可以 **设置值…**(`F2`)、**复制值**、**复制名称**、**跳转到源代码**(`F4`)和 **添加到监视**。 -- 监视表达式显示在变量视图顶部,每次停下或切换帧时重新计算。用 **添加到监视** 添加,用 **移除监视** 删除。 +- 监视表达式显示在变量视图顶部,每次停下或切换帧时重新计算。用 **添加到监视** 添加,用 **移除监视** 删除,用 **移除所有监视** 一次全部删除。 - 在编辑器里悬停变量会显示它的值。`⌥` 点击(`Alt` 点击)或 **快速计算表达式**(`⌘⌥F8` / `Ctrl+Alt+F8`)计算鼠标下的表达式或选中的内容。 - 局部变量的值会内联显示在使用它们的行尾。 - **计算表达式…**(`⌥F8` / `Alt+F8`)打开对话框,在选中帧里计算任意表达式,带历史记录,也能把表达式加入监视。 diff --git a/src/features/debugger/__tests__/toolWindow.test.tsx b/src/features/debugger/__tests__/toolWindow.test.tsx index cf291552b..99abdee4d 100644 --- a/src/features/debugger/__tests__/toolWindow.test.tsx +++ b/src/features/debugger/__tests__/toolWindow.test.tsx @@ -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…"); diff --git a/src/features/debugger/__tests__/watchStorage.test.ts b/src/features/debugger/__tests__/watchStorage.test.ts index 48386436f..ce477b943 100644 --- a/src/features/debugger/__tests__/watchStorage.test.ts +++ b/src/features/debugger/__tests__/watchStorage.test.ts @@ -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"); diff --git a/src/features/debugger/state.ts b/src/features/debugger/state.ts index 9014a529f..6c20e4f84 100644 --- a/src/features/debugger/state.ts +++ b/src/features/debugger/state.ts @@ -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}`; diff --git a/src/features/debugger/ui/VariablesView.tsx b/src/features/debugger/ui/VariablesView.tsx index 214e69a92..82ae6a1fd 100644 --- a/src/features/debugger/ui/VariablesView.tsx +++ b/src/features/debugger/ui/VariablesView.tsx @@ -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) }); diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 021658d21..421a4ae7d 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2706,5 +2706,6 @@ "": "", "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" } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 8effb4217..4b38660dc 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -9073,5 +9073,6 @@ "Resize shelf panes": "调整搁置记录和文件窗格大小", "Database and schema": "数据库和 schema", "Shelve Silently": "静默搁置", - "Unshelve Silently": "静默取消搁置" + "Unshelve Silently": "静默取消搁置", + "Remove All Watches": "移除所有监视" }