From ebc6dc86f12da0442e50cd7632378445f6edc010 Mon Sep 17 00:00:00 2001 From: Muu Date: Sun, 29 Nov 2026 10:34:17 +0800 Subject: [PATCH] feat(project-tree): show file size and modification details (#6613) Project view Options > Appearance > File Details shows each file's modification date and time and its size beside its name, as IDEA's File Details does. Off by default, persisted with the other view options; a missing modification time shows only the size. Co-authored-by: muutot <92625353+muutot@users.noreply.github.com> --- docs/en/guide/quickstart.mdx | 2 + docs/zh/guide/quickstart.mdx | 2 + src/features/project-tree/HeaderActions.tsx | 1 + .../project-tree/ProjectView.test.tsx | 78 ++++++++++++++++++- src/features/project-tree/ProjectView.tsx | 30 ++++++- src/features/project-tree/store.test.ts | 9 +++ src/features/project-tree/store.ts | 3 + src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh-TW.json | 1 + src/platform/locales/text/zh.json | 1 + 10 files changed, 126 insertions(+), 2 deletions(-) diff --git a/docs/en/guide/quickstart.mdx b/docs/en/guide/quickstart.mdx index ed3de36bf..7170875db 100644 --- a/docs/en/guide/quickstart.mdx +++ b/docs/en/guide/quickstart.mdx @@ -48,6 +48,8 @@ When a language needs a language server that isn't installed, a notification nam `⇧⇧` means pressing Shift twice. **Find Action** is the fastest way to discover a feature: type a few words of what you want. For more, see [Search and navigation](/en/guide/search) and the full [shortcut reference](/en/reference/shortcuts). +In the Project tool window, **Options › Appearance › File Details** shows each file's modification date and time and its size beside its name. It is off by default and remembered across sessions; when a modification time is unavailable, only the size is shown. + ## Run OpenIDEA detects what can run in your project and shows a run icon in the gutter next to entry points and tests. diff --git a/docs/zh/guide/quickstart.mdx b/docs/zh/guide/quickstart.mdx index 65237dfa1..e5191ded2 100644 --- a/docs/zh/guide/quickstart.mdx +++ b/docs/zh/guide/quickstart.mdx @@ -48,6 +48,8 @@ OpenIDEA 把一个文件夹作为项目打开,以下方式都可以: `⇧⇧` 表示连按两下 Shift。想找某个功能时,**查找操作** 最快:输入几个关键词即可。更多内容参见[搜索与导航](/zh/guide/search)和完整的[快捷键表](/zh/reference/shortcuts)。 +在项目工具窗口中,**选项 › 外观 › 文件详情** 会在每个文件名旁显示修改日期时间和大小。该选项默认关闭并跨会话记住;若修改时间不可用,则只显示大小。 + ## 运行 OpenIDEA 会识别项目中可以运行的内容,在入口函数和测试旁的边栏显示运行图标。 diff --git a/src/features/project-tree/HeaderActions.tsx b/src/features/project-tree/HeaderActions.tsx index d254bd545..44c6fcf8b 100644 --- a/src/features/project-tree/HeaderActions.tsx +++ b/src/features/project-tree/HeaderActions.tsx @@ -73,6 +73,7 @@ const APPEARANCE_OPTIONS: Array<[ToggleOption, string]> = [ ["showMembers", "Show Members"], ["showScratches", "Show Scratches and Consoles"], ["showRootPaths", "Show Root Paths"], + ["showFileDetails", "File Details"], ["horizontalScroll", "Horizontal Scrolling"], ["compact", "Compact Middle Packages"], ]; diff --git a/src/features/project-tree/ProjectView.test.tsx b/src/features/project-tree/ProjectView.test.tsx index f8ec91f9c..2caea5ed9 100644 --- a/src/features/project-tree/ProjectView.test.tsx +++ b/src/features/project-tree/ProjectView.test.tsx @@ -17,7 +17,7 @@ import { MemoryFs, setProjectFsForTests } from "./fs"; import { MessagesHost } from "@/workbench/messages"; import { FileRefactorDialogHost } from "./FileRefactorDialogs"; import { setRefactorBackendForTests } from "./fileRefactor"; -import { ProjectView } from "./ProjectView"; +import { ProjectView, formatFileDetails } from "./ProjectView"; import { beginNew, beginRename, canPaste } from "./operations"; import { initProjectTree, selectModel, setSelection, setViewOption, useProjectTree } from "./store"; import type { OutlineItem } from "@/bindings"; @@ -1184,6 +1184,82 @@ it("hides the path beside workspace roots when Show Root Paths is off, keeping i act(() => setViewOption("showRootPaths", true)); }); +describe("File Details", () => { + const modifiedAt = new Date(2026, 10, 28, 12).getTime(); + const modified = "28.11.2026 12:00"; + + beforeEach(() => { + useProject.setState({ + settings: { + general: { + dateFormat: { overrideSystem: true, pattern: "dd.MM.yyyy", use24Hour: true, pretty: false }, + }, + }, + }); + }); + + it("formats concise sizes and the configured modification date", () => { + expect(formatFileDetails(null)).toBeNull(); + expect(formatFileDetails({ size: 0, mtimeMs: modifiedAt })).toBe(`${modified}, 0 B`); + expect(formatFileDetails({ size: 1023, mtimeMs: modifiedAt })).toBe(`${modified}, 1023 B`); + expect(formatFileDetails({ size: 1024, mtimeMs: modifiedAt })).toBe(`${modified}, 1 KB`); + expect(formatFileDetails({ size: 1536, mtimeMs: modifiedAt })).toBe(`${modified}, 1.5 KB`); + expect(formatFileDetails({ size: 1_048_575, mtimeMs: modifiedAt })).toBe(`${modified}, 1 MB`); + }); + + it.each([null, 0])("shows only the size when mtimeMs is %s", (mtimeMs) => { + expect(formatFileDetails({ size: 512, mtimeMs })).toBe("512 B"); + }); + + it("toggles File Details from Appearance and persists the option", () => { + const { result } = renderHook(() => useProjectHeaderMenu()); + type Item = Extract; + const toggle = () => + ((result.current.find((item) => "label" in item && item.label === "Appearance") as Item).submenu as Item[]).find( + (item) => item.id === "showFileDetails", + )!; + expect(toggle()).toMatchObject({ label: "File Details", checked: false }); + + act(() => toggle().run!()); + expect(toggle().checked).toBe(true); + expect(JSON.parse(localStorage.getItem("openidea.projectTree.options")!)).toMatchObject({ showFileDetails: true }); + const action = getAction("project.option.showFileDetails")!; + expect(action.toggled!()).toBe(true); + + act(() => void executeAction(action.id)); + expect(toggle().checked).toBe(false); + expect(JSON.parse(localStorage.getItem("openidea.projectTree.options")!)).toMatchObject({ showFileDetails: false }); + }); + + it("renders metadata on file rows only without changing root paths", async () => { + const readDir = fs.readDir.bind(fs); + vi.spyOn(fs, "readDir").mockImplementation(async (path) => + (await readDir(path)).map((entry) => ({ + ...entry, + size: entry.kind === "file" ? 1536 : 2048, + mtimeMs: modifiedAt, + })), + ); + const { row, rows } = setup(); + await waitFor(() => expect(rows()).toContain("README.md")); + expect(row("acme").textContent).toBe("acme/w/acme"); + expect(row("src").textContent).toBe("src"); + expect(row("build").textContent).toBe("build"); + + act(() => setViewOption("showFileDetails", true)); + const detail = `${modified}, 1.5 KB`; + expect(row("README.md").textContent).toBe(`README.md${detail}`); + expect(within(row("README.md")).getByTitle(detail)).toBeInTheDocument(); + expect(row("acme").textContent).toBe("acme/w/acme"); + expect(row("src").textContent).toBe("src"); + expect(row("build").textContent).toBe("build"); + + act(() => setViewOption("showFileDetails", false)); + expect(row("README.md").textContent).toBe("README.md"); + expect(row("acme").textContent).toBe("acme/w/acme"); + }); +}); + it("shows a decoration's suffix after the root name, with icons and struck-out segments", async () => { const { row } = setup(); await waitFor(() => expect(row("acme")).toBeTruthy()); diff --git a/src/features/project-tree/ProjectView.tsx b/src/features/project-tree/ProjectView.tsx index c4507b21e..9ba759eb0 100644 --- a/src/features/project-tree/ProjectView.tsx +++ b/src/features/project-tree/ProjectView.tsx @@ -19,8 +19,10 @@ import { } from "react"; import { createPortal } from "react-dom"; import clsx from "clsx"; +import type { FileEntry } from "@/bindings"; import { revealRange, useEditorRegistry } from "@/editor/api"; import { executeAction } from "@/platform/actions"; +import { formatDateTime } from "@/platform/dateFormat"; import { tx, useTxTemplate } from "@/platform/i18n"; import { isTauri } from "@/platform/ipc"; import { canDragOut, dragOut, isDraggingOut } from "@/platform/dragOut"; @@ -265,6 +267,27 @@ function InlineEditor({ editing, initial, onDone }: { editing: Editing; initial: // --------------------------------------------------------------------------- // Rows +const FILE_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"]; + +function formatFileSize(bytes: number): string { + let value = bytes; + let unit = 0; + // Promote values that round to 1024 so the next unit starts cleanly. + while (unit < FILE_SIZE_UNITS.length - 1 && Number(value.toFixed(1)) >= 1024) { + value /= 1024; + unit++; + } + return `${unit === 0 ? value : Number(value.toFixed(1))} ${FILE_SIZE_UNITS[unit]}`; +} + +/** IDEA's File Details: modification date and time, then size; zero means the backend has no modification time. */ +export function formatFileDetails(entry: Pick | null): string | null { + if (!entry) return null; + const size = formatFileSize(entry.size); + const modified = entry.mtimeMs ? formatDateTime(new Date(entry.mtimeMs)) : null; + return modified ? `${modified}, ${size}` : size; +} + interface RowProps { node: ProjectNode; matches: number[] | null; @@ -925,7 +948,11 @@ export function ProjectView() { editing={editing} cut={cutPaths.has(node.path)} dropTarget={dropTarget === node.key} - detail={node.detail ?? (rootPath(node) && options.showRootPaths ? rootPath(node) : null)} + detail={ + node.detail ?? + (rootPath(node) && options.showRootPaths ? rootPath(node) : null) ?? + (options.showFileDetails && !node.dir ? formatFileDetails(node.entry) : null) + } hint={rootPath(node)} onEditDone={focusTree} onClick={onRowClick} @@ -938,6 +965,7 @@ export function ProjectView() { cutPaths, dropTarget, options.showRootPaths, + options.showFileDetails, rootPath, focusTree, onRowClick, diff --git a/src/features/project-tree/store.test.ts b/src/features/project-tree/store.test.ts index 5c331991a..685bf4798 100644 --- a/src/features/project-tree/store.test.ts +++ b/src/features/project-tree/store.test.ts @@ -508,6 +508,15 @@ describe("single-click expansion", () => { }); }); +it("keeps File Details off by default and persists the option across reloads", async () => { + expect(useProjectTree.getState().options.showFileDetails).toBe(false); + setViewOption("showFileDetails", true); + vi.resetModules(); + const fresh = await import("./store"); + expect(fresh.useProjectTree.getState().options.showFileDetails).toBe(true); + setViewOption("showFileDetails", false); +}); + it("keeps the primary first and sorts attachments by name", () => { initProjectTree("/z", "Z", ["/z", "/c", "/a"]); expect(currentModel().roots.map((n) => n.path)).toEqual(["/z", "/a", "/c"]); diff --git a/src/features/project-tree/store.ts b/src/features/project-tree/store.ts index 1496be529..b12d4cd16 100644 --- a/src/features/project-tree/store.ts +++ b/src/features/project-tree/store.ts @@ -66,6 +66,8 @@ export interface ViewOptions extends TreeOptions { showMembers: boolean; /** Show the location of each project root beside its name. */ showRootPaths: boolean; + /** Show each file's size and modification date beside its name. */ + showFileDetails: boolean; /** List Scratches and Consoles below the project in the Project pane. */ showScratches: boolean; /** Rows wider than the pane scroll sideways; off clips long names (VS Code's horizontal scrolling). */ @@ -80,6 +82,7 @@ export const DEFAULT_VIEW_OPTIONS: ViewOptions = { singleClickExpand: false, showMembers: false, showRootPaths: true, + showFileDetails: false, showScratches: true, horizontalScroll: true, }; diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index dd3d99c3b..d3ec2e57c 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2069,6 +2069,7 @@ "Type": "Type", "Modification Time": "Modification Time", "Show Root Paths": "Show Root Paths", + "File Details": "File Details", "Workspace": "Workspace", "Disable Server": "Disable Server", "Enable Server": "Enable Server", diff --git a/src/platform/locales/text/zh-TW.json b/src/platform/locales/text/zh-TW.json index d06affa32..7ebf092c7 100644 --- a/src/platform/locales/text/zh-TW.json +++ b/src/platform/locales/text/zh-TW.json @@ -7941,6 +7941,7 @@ "{names} need {name} and stop while it is disabled. Disable it anyway?": "{names} 依賴 {name},在其被停用期間將停止執行。仍要停用嗎?", "{names} needs {name} and stops while it is disabled. Disable it anyway?": "{names} 依賴 {name},在其被停用期間將停止執行。仍要停用嗎?", "Show Root Paths": "顯示根路徑", + "File Details": "顯示檔案詳細資訊", "Workspace": "工作區", "Disable Server": "停用伺服器", "Enable Server": "啟用伺服器", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 1956a89ca..9d295ee8d 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -8747,6 +8747,7 @@ "{names} need {name} and stop while it is disabled. Disable it anyway?": "{names} 依赖 {name},在其被禁用期间将停止运行。仍要禁用吗?", "{names} needs {name} and stops while it is disabled. Disable it anyway?": "{names} 依赖 {name},在其被禁用期间将停止运行。仍要禁用吗?", "Show Root Paths": "显示根路径", + "File Details": "显示文件详细信息", "Workspace": "工作区", "Disable Server": "禁用服务器", "Enable Server": "启用服务器",