дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
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 <[email protected]>
Цей коміт міститься в:
1 джерело
1eece0ae51
коміт
f4236a0ea1
4 files changed
+103
-4
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ description: "编辑器和问题工具窗口中的问题、快速修复与意图
|
||||
| **错误描述** | `⌘F1` | `Ctrl+F1` |
|
||||
| **问题** 工具窗口 | `⌘6` | `Alt+6` |
|
||||
|
||||
**问题** 工具窗口有两个标签页:**文件**(当前编辑器)和 **项目错误**。在它的选项菜单中可以按严重性或名称排序、显示预览、自动滚动到源代码。
|
||||
**问题** 工具窗口有两个标签页:**文件**(当前编辑器)和 **项目错误**。问题按文件分组,工具栏上的 **全部展开** / **全部折叠** 可以展开或折叠所有文件。在它的选项菜单中可以按严重性或名称排序、显示预览、自动滚动到源代码。
|
||||
|
||||
## 快速修复与意图操作
|
||||
|
||||
|
||||
@@ -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(<ProblemsView />);
|
||||
|
||||
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(<ProblemsView />);
|
||||
|
||||
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(<ProblemsView />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Collapse All" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Expand All" }));
|
||||
expect(screen.getByText("No problems found")).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -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 (
|
||||
<Toolbar aria-label="Problems actions" orientation={orientation} className={styles.toolbar}>
|
||||
<IconButton icon="arrow-up" action="navigate.prevOccurrence" size="small" />
|
||||
<IconButton icon="arrow-down" action="navigate.nextOccurrence" size="small" />
|
||||
<IconButton icon="expand-all" title="Expand All" size="small" onClick={() => onCollapseAll(false)} />
|
||||
<IconButton icon="collapse-all" title="Collapse All" size="small" onClick={() => onCollapseAll(true)} />
|
||||
<IconButton icon="error" title="Show Errors" size="small" pressed={show.error} onClick={() => toggle("error")} />
|
||||
<IconButton
|
||||
icon="warning"
|
||||
@@ -479,7 +487,20 @@ export function ProblemsView() {
|
||||
);
|
||||
const list = (
|
||||
<div className={clsx(styles.results, sideDocked && styles.resultsStacked)}>
|
||||
<ProblemsToolbar orientation={sideDocked ? "horizontal" : "vertical"} />
|
||||
<ProblemsToolbar
|
||||
orientation={sideDocked ? "horizontal" : "vertical"}
|
||||
onCollapseAll={(collapse) =>
|
||||
// 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}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Заблокувати користувача