Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions apps/desktop/src/ui/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
splitRows,
} from "../state/diff";
import { loadPullDiff, prefetchPullDiff, usePullList } from "../state/pullQueries";
import { pullDiffFiles } from "../state/pullReview";
import {
draftCounts,
EMPTY_DRAFT,
Expand Down Expand Up @@ -57,10 +58,13 @@ import { DiffCount } from "./Rows";

interface ReviewFile {
path: string;
/** The path before a rename. */
oldPath?: string;
status: string;
added: number;
removed: number;
lines: PatchLine[];
binary?: boolean;
}

type Source =
Expand Down Expand Up @@ -399,17 +403,15 @@ export function Review({ threadId }: { threadId: string }) {
if (answer.error) {
throw new Error(`${pullErrorTitle(answer.error.code)}: ${answer.error.message}`);
}
const chunks = splitUnifiedDiff(answer.diff ?? "");
out = Object.entries(chunks).map(([path, lines]) => {
const parsed = parsePatch(lines);
return {
path,
status: "M",
added: parsed.filter((l) => l.kind === "add").length,
removed: parsed.filter((l) => l.kind === "del").length,
lines: parsed,
};
});
out = pullDiffFiles(answer.diff ?? "").map((f) => ({
path: f.path,
...(f.oldPath ? { oldPath: f.oldPath } : {}),
status: f.status,
added: f.added,
removed: f.removed,
lines: f.lines,
binary: f.binary,
}));
} else {
const folder = source.kind === "branch" && wt ? wt.path : cwd;
const changes = await gitChanges(folder, source.kind === "branch" ? wt?.base : undefined);
Expand All @@ -418,7 +420,9 @@ export function Review({ threadId }: { threadId: string }) {
const chunks = splitUnifiedDiff(changes.diff);
out = changes.files.map((f) => ({
path: f.path,
...(f.oldPath ? { oldPath: f.oldPath } : {}),
status: f.status,
binary: f.binary,
added: f.added,
removed: f.removed,
lines: parsePatch(chunks[f.path] ?? []),
Expand Down Expand Up @@ -592,7 +596,7 @@ export function Review({ threadId }: { threadId: string }) {
const f = files?.find((x) => x.path === path);
const n = comments.filter((c) => c.path === path).length;
return (
<Tooltip key={path} label={path} side="right">
<Tooltip key={path} label={f?.oldPath ? `${f.oldPath} → ${path}` : path} side="right">
<button
type="button"
onClick={() => setSelected(path)}
Expand Down Expand Up @@ -652,7 +656,9 @@ export function Review({ threadId }: { threadId: string }) {
)}
</button>
<FileDiff size={13} className="shrink-0 text-fg-muted" />
<span className="selectable min-w-0 truncate font-mono">{file.path}</span>
<span className="selectable min-w-0 truncate font-mono">
{file.oldPath ? `${file.oldPath} → ${file.path}` : file.path}
</span>
<DiffCount added={file.added} removed={file.removed} />
<span className="flex-1" />
<span className="shrink-0 text-caption text-fg-faint max-[1099px]:hidden">
Expand All @@ -670,7 +676,9 @@ export function Review({ threadId }: { threadId: string }) {
onRemove={(c) => setComments((all) => all.filter((x) => x !== c))}
/>
) : (
<p className="text-callout text-fg-muted">No text diff (a binary or very large file).</p>
<p className="text-callout text-fg-muted">
{file.binary ? "A binary file: no lines to show." : "No text diff to show."}
</p>
)}
</div>
</>
Expand Down
Loading