Skip to content

Commit f35aeed

Browse files
committed
fix(chat): rely on computeDiffStats for new file unified diffs; remove special-case counting and add test (addresses roomote review)\n\n- Remove special-case line counting for newFileCreated in [diffStatsForInline](webview-ui/src/components/chat/ChatRow.tsx:472)\n- Always use [computeDiffStats()](webview-ui/src/components/chat/ChatRow.tsx:118)\n- Add test to assert +N/-0 for new files in [ChatRow.diff-actions.spec.tsx](webview-ui/src/components/chat/__tests__/ChatRow.diff-actions.spec.tsx)
1 parent 4f060c7 commit f35aeed

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,8 @@ export const ChatRowContent = ({
470470
}, [tool])
471471

472472
const diffStatsForInline = useMemo(() => {
473-
if (tool?.tool === "newFileCreated") {
474-
// For new files, count all lines as additions
475-
const content = diffTextForStats
476-
if (!content) return null
477-
const lines = content.split("\n").length
478-
return { added: lines, removed: 0 }
479-
}
480473
return computeDiffStats(diffTextForStats)
481-
}, [diffTextForStats, tool])
474+
}, [diffTextForStats])
482475

483476
// Clean diff content for display (remove CDATA markers and convert to unified diff)
484477
const cleanDiffContent = useMemo(() => {

webview-ui/src/components/chat/__tests__/ChatRow.diff-actions.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,25 @@ describe("ChatRow - inline diff stats and actions", () => {
9090
expect(screen.getByText("+1")).toBeInTheDocument()
9191
expect(screen.getByText("-2")).toBeInTheDocument()
9292
})
93+
94+
it("counts only added lines for newFileCreated (ignores diff headers)", () => {
95+
const content = "a\nb\nc"
96+
const message: any = {
97+
type: "ask",
98+
ask: "tool",
99+
ts: Date.now(),
100+
partial: false,
101+
text: JSON.stringify({
102+
tool: "newFileCreated",
103+
path: "src/new-file.ts",
104+
content,
105+
}),
106+
}
107+
108+
renderChatRow(message)
109+
110+
// Should only count the three content lines as additions
111+
expect(screen.getByText("+3")).toBeInTheDocument()
112+
expect(screen.getByText("-0")).toBeInTheDocument()
113+
})
93114
})

0 commit comments

Comments
 (0)