From f4236a0ea10861cf00fc0b90b6a49e6e20a29256 Mon Sep 17 00:00:00 2001 From: Mansur Akhmadi Date: Wed, 2 Dec 2026 10:20:51 +0700 Subject: [PATCH] feat(problems): Expand All / Collapse All in the Problems tool window toolbar (#7325) The Problems toolbar gets Expand All and Collapse All; they touch only the files the current tab shows. Closes #7324 Co-authored-by: mansur-akhmadi <10739460+mansur-akhmadi@users.noreply.github.com> --- docs/en/guide/inspections.mdx | 2 +- docs/zh/guide/inspections.mdx | 2 +- .../code-insight/ProblemsView.test.tsx | 78 +++++++++++++++++++ src/features/code-insight/ProblemsView.tsx | 25 +++++- 4 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 src/features/code-insight/ProblemsView.test.tsx diff --git a/docs/en/guide/inspections.mdx b/docs/en/guide/inspections.mdx index 1eb0b70fd2..773de8a98d 100644 --- a/docs/en/guide/inspections.mdx +++ b/docs/en/guide/inspections.mdx @@ -16,7 +16,7 @@ Problems are underlined in the editor and marked in the scrollbar. The widget at | **Error Description** | `⌘F1` | `Ctrl+F1` | | **Problems** tool window | `⌘6` | `Alt+6` | -The **Problems** tool window has two tabs: **File** (the current editor) and **Project Errors**. Its options menu sorts by severity or name, shows a preview and can autoscroll to the source. +The **Problems** tool window has two tabs: **File** (the current editor) and **Project Errors**. Problems are grouped by file; the toolbar has **Expand All** / **Collapse All** for the files. Its options menu sorts by severity or name, shows a preview and can autoscroll to the source. ## Quick fixes and intentions diff --git a/docs/zh/guide/inspections.mdx b/docs/zh/guide/inspections.mdx index 137aa247f4..edd832511d 100644 --- a/docs/zh/guide/inspections.mdx +++ b/docs/zh/guide/inspections.mdx @@ -16,7 +16,7 @@ description: "编辑器和问题工具窗口中的问题、快速修复与意图 | **错误描述** | `⌘F1` | `Ctrl+F1` | | **问题** 工具窗口 | `⌘6` | `Alt+6` | -**问题** 工具窗口有两个标签页:**文件**(当前编辑器)和 **项目错误**。在它的选项菜单中可以按严重性或名称排序、显示预览、自动滚动到源代码。 +**问题** 工具窗口有两个标签页:**文件**(当前编辑器)和 **项目错误**。问题按文件分组,工具栏上的 **全部展开** / **全部折叠** 可以展开或折叠所有文件。在它的选项菜单中可以按严重性或名称排序、显示预览、自动滚动到源代码。 ## 快速修复与意图操作 diff --git a/src/features/code-insight/ProblemsView.test.tsx b/src/features/code-insight/ProblemsView.test.tsx new file mode 100644 index 0000000000..8e0009e40a --- /dev/null +++ b/src/features/code-insight/ProblemsView.test.tsx @@ -0,0 +1,78 @@ +import { act, fireEvent, render, screen } from "@testing-library/react"; +import { afterEach, describe, expect, it } from "vitest"; +import type { Diagnostic } from "@/bindings"; +import { ProblemsView, useProblemsView } from "./ProblemsView"; +import { applyDiagnosticsEvent, clearProblems } from "./problemsStore"; + +const problem = (line: number, message: string): Diagnostic => + ({ + range: { start: { line, col: 0 }, end: { line, col: 4 } }, + severity: "error", + message, + source: null, + code: null, + }) as Diagnostic; + +describe("ProblemsView", () => { + const initialView = useProblemsView.getState(); + afterEach(() => { + act(() => { + clearProblems(); + useProblemsView.setState(initialView); + }); + }); + + it("expands and collapses every file from the toolbar, as IDEA", () => { + act(() => { + clearProblems(); + applyDiagnosticsEvent("/p/src/a.ts", "lsp", [problem(0, "alpha broke")]); + applyDiagnosticsEvent("/p/src/b.ts", "lsp", [problem(1, "beta broke"), problem(2, "gamma broke")]); + useProblemsView.setState({ tab: "project" }); + }); + render(); + + fireEvent.click(screen.getByRole("button", { name: "Collapse All" })); + expect(screen.queryByText("alpha broke")).toBeNull(); + expect(screen.queryByText("beta broke")).toBeNull(); + expect(screen.getByText("a.ts")).toBeVisible(); + expect(screen.getByText("b.ts")).toBeVisible(); + + fireEvent.click(screen.getByRole("button", { name: "Expand All" })); + expect(screen.getByText("alpha broke")).toBeVisible(); + expect(screen.getByText("beta broke")).toBeVisible(); + expect(screen.getByText("gamma broke")).toBeVisible(); + }); + + it("leaves collapsed files collapsed on a second Collapse All and expands files reported later", () => { + act(() => { + clearProblems(); + applyDiagnosticsEvent("/p/src/a.ts", "lsp", [problem(0, "alpha broke")]); + useProblemsView.setState({ tab: "project" }); + }); + render(); + + fireEvent.click(screen.getByRole("button", { name: "Collapse All" })); + fireEvent.click(screen.getByRole("button", { name: "Collapse All" })); + expect(screen.queryByText("alpha broke")).toBeNull(); + + // A file that reports after Collapse All starts expanded, as IDEA's new nodes do. + act(() => applyDiagnosticsEvent("/p/src/c.ts", "lsp", [problem(3, "delta broke")])); + expect(screen.getByText("delta broke")).toBeVisible(); + expect(screen.queryByText("alpha broke")).toBeNull(); + + fireEvent.click(screen.getByRole("button", { name: "Expand All" })); + expect(screen.getByText("alpha broke")).toBeVisible(); + expect(screen.getByText("delta broke")).toBeVisible(); + }); + + it("does nothing when there are no problems", () => { + act(() => { + clearProblems(); + useProblemsView.setState({ tab: "project" }); + }); + render(); + fireEvent.click(screen.getByRole("button", { name: "Collapse All" })); + fireEvent.click(screen.getByRole("button", { name: "Expand All" })); + expect(screen.getByText("No problems found")).toBeVisible(); + }); +}); diff --git a/src/features/code-insight/ProblemsView.tsx b/src/features/code-insight/ProblemsView.tsx index fdf0f97149..860a4a2fec 100644 --- a/src/features/code-insight/ProblemsView.tsx +++ b/src/features/code-insight/ProblemsView.tsx @@ -234,13 +234,21 @@ function useCurrentPath(): string | null { return currentProblemsPath(text, useSyncExternalStore(subscribeActiveInput, activeInput)); } -function ProblemsToolbar({ orientation }: { orientation: "horizontal" | "vertical" }) { +function ProblemsToolbar({ + orientation, + onCollapseAll, +}: { + orientation: "horizontal" | "vertical"; + onCollapseAll: (collapse: boolean) => void; +}) { const show = useProblemsView((s) => s.show); const toggle = useProblemsView((s) => s.toggle); return ( + onCollapseAll(false)} /> + onCollapseAll(true)} /> toggle("error")} /> - + + // Touch only the files shown; the rest keep their state for the other tab. + setCollapsed((prev) => { + const s = new Set(prev); + for (const { key } of roots) { + if (collapse) s.add(key); + else s.delete(key); + } + return s; + }) + } + /> {treeView} );