diff --git a/src/features/vcs/ComparisonTree.tsx b/src/features/vcs/ComparisonTree.tsx index d953d740e..5defe247f 100644 --- a/src/features/vcs/ComparisonTree.tsx +++ b/src/features/vcs/ComparisonTree.tsx @@ -12,6 +12,7 @@ export function ComparisonTree({ current, onSelect, diffFor, + renderFileIcon, renderDetails, ariaLabel, openOnActivate = false, @@ -23,6 +24,7 @@ export function ComparisonTree({ current: F | null; onSelect: (entry: F | null) => void; diffFor: (entry: F) => DiffData | null; + renderFileIcon?: (file: F) => ReactNode; renderDetails: (node: FileTreeNode) => ReactNode; ariaLabel: string; openOnActivate?: boolean; @@ -64,7 +66,7 @@ export function ComparisonTree({ className={styles.comparisonTree} renderNode={(n) => ( - + {(n.file && renderFileIcon?.(n.file)) ?? } {n.name} diff --git a/src/features/vcs/__tests__/compareTool.test.tsx b/src/features/vcs/__tests__/compareTool.test.tsx index 9b29457e2..5f431a7cf 100644 --- a/src/features/vcs/__tests__/compareTool.test.tsx +++ b/src/features/vcs/__tests__/compareTool.test.tsx @@ -3,6 +3,8 @@ import { cleanup, fireEvent, render, screen } from "@testing-library/react"; const mocks = vi.hoisted(() => ({ worktree: vi.fn(), + revisions: vi.fn(), + presentations: vi.fn(), openDiff: vi.fn(), openFile: vi.fn(), })); @@ -10,9 +12,19 @@ vi.mock("@/platform/ipc", async (original) => { const real = await original(); return { ...real, - commands: { ...real.commands, vcsDiffWithWorktree: mocks.worktree }, + isTauri: () => true, + commands: { + ...real.commands, + vcsDiffWithWorktree: mocks.worktree, + vcsDiffRevisions: mocks.revisions, + jvmFilePresentations: mocks.presentations, + }, }; }); +vi.mock("@/ui", async (original) => ({ + ...(await original()), + Icon: ({ name }: { name: string }) => , +})); vi.mock("../diffInput", async (original) => { const real = await original(); return { ...real, openVcsDiff: mocks.openDiff }; @@ -25,7 +37,7 @@ vi.mock("@/workbench/contributions", async (original) => { return { ...real, maybeEditorService: () => ({ openFile: mocks.openFile }) }; }); import { useProject } from "@/platform/project"; -import { comparisonDiffData, type ComparisonFile } from "../operations"; +import { ChangesBetweenDialog, comparisonDiffData, type ComparisonFile } from "../operations"; import { CompareToolWindow, useCompareTool } from "../compareTool"; import { useVcs } from "../store"; @@ -114,6 +126,47 @@ describe("CompareToolWindow", () => { expect(mocks.openFile).toHaveBeenCalledWith("/workspace/client/src/app.ts", { focus: true }); }); + it("shows Java and Kotlin declarations from the compared repository and skips deleted files", async () => { + const base = "/workspace/client/src/"; + mocks.worktree.mockResolvedValue({ + status: "ok", + data: [ + { ...modified, path: "src/PricingRule.java", kind: "renamed", oldPath: "src/Rule.java" }, + { ...modified, path: "src/Order.java" }, + { ...modified, path: "src/OrderTest.java", kind: "added" }, + { ...modified, path: "src/Removed.java", kind: "deleted" }, + { ...modified, path: "src/Pricing.kt" }, + modified, + ], + }); + mocks.presentations.mockResolvedValue({ + status: "ok", + data: [ + { path: base + "PricingRule.java", presentation: { kind: "interface" } }, + { path: base + "Order.java", presentation: { kind: "class" } }, + { path: base + "OrderTest.java", presentation: { kind: "class" } }, + { path: base + "Pricing.kt", presentation: { kind: "object" } }, + ], + }); + render(); + expect(await screen.findByTestId("icon-interface")).toBeInTheDocument(); + expect(screen.getByText("PricingRule.java").previousElementSibling).toBe(screen.getByTestId("icon-interface")); + expect(screen.getByText("Order.java").previousElementSibling).toBe(screen.getByTestId("icon-class")); + expect(screen.getByText("OrderTest.java").previousElementSibling).toBe(screen.getByTestId("icon-jvm-test")); + expect(screen.getByText("Removed.java").previousElementSibling).toBe(screen.getByTestId("icon-file-java")); + expect(screen.getByText("Pricing.kt").previousElementSibling).toBe(screen.getByTestId("icon-kotlin-object")); + expect(mocks.presentations.mock.calls.flatMap(([paths]) => paths).sort()).toEqual( + ["Order.java", "OrderTest.java", "Pricing.kt", "PricingRule.java"].map((name) => base + name), + ); + }); + + it("keeps the file-type icon for a comparison of two revisions", async () => { + mocks.revisions.mockResolvedValue({ status: "ok", data: [{ ...modified, path: "src/PricingRule.java" }] }); + render( {}} />); + expect(await screen.findByTestId("icon-file-java")).toBeInTheDocument(); + expect(mocks.presentations).not.toHaveBeenCalled(); + }); + it("lists files without an inline diff and opens a file's diff in the editor", async () => { mocks.openDiff.mockResolvedValue(undefined); render(); diff --git a/src/features/vcs/operations.tsx b/src/features/vcs/operations.tsx index c51833306..ff4b237f0 100644 --- a/src/features/vcs/operations.tsx +++ b/src/features/vcs/operations.tsx @@ -9,6 +9,7 @@ import type { ChangedFile, Commit, CompareResult, ResetMode, WorkingTreeChange } import { executeAction } from "@/platform/actions"; import { call, commands, isTauri, nextRequestId } from "@/platform/ipc"; import { Button, Checkbox, Dialog, Icon, Input, Spinner, T } from "@/ui"; +import { useFilePresentation } from "@/ui/filePresentation"; import { notifications } from "@/workbench/contributions"; import { windowBackgroundHex } from "@/workbench/theme"; import { diffInput, openVcsDiff, vcsDiffInFront, type DiffData, type DiffSide } from "./diffInput"; @@ -614,6 +615,17 @@ export interface ComparisonFile extends ChangedFile { removed?: number; } +function WorktreeFileIcon({ path }: { path: string }) { + const { icon } = useFilePresentation(path); + return ; +} + +/** A working-tree file shows the Project tree's icon (Java and Kotlin declarations, Spring config). */ +function renderWorktreeFileIcon(file: ComparisonFile) { + if (!file.root || file.kind === "deleted") return null; + return ; +} + /** * Diff content of one comparison file. `swapped` exchanges the two sides * (the Compare tool window's Swap Sides), for worktree and revision diffs alike. @@ -804,6 +816,7 @@ export function ChangesBetweenDialog({ current={current} onSelect={setCurrent} diffFor={diffFor} + renderFileIcon={listOnly && !to ? renderWorktreeFileIcon : undefined} getColor={(f) => KIND_COLOR[f.kind === "untracked" ? "added" : f.kind]} ariaLabel="Changed files" inlineDiff={!listOnly}