Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions webview-ui/playwright/gallery/stories.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions webview-ui/src/__tests__/FileChangesPanel.spec.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro

{task && (
<>
<div className="grow flex" ref={scrollContainerRef}>
<div className="grow min-h-0 flex" ref={scrollContainerRef}>
<Virtuoso
ref={virtuosoRef}
key={task.ts}
Expand Down
47 changes: 36 additions & 11 deletions webview-ui/src/components/chat/FileChangesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@
// `ts` is not unique, so the message's own id identifies it; `ts` only covers messages persisted without one.
const originalKey = (entry: { messageId?: string; ts: number }) => entry.messageId ?? `ts:${entry.ts}`

// The number of edits distinguishes legacy siblings that share a timestamp.
const fileRevision = (entries: FileChangeEntry[]) => {
const last = entries.at(-1)!
return { key: entries.length + ":" + originalKey(last), diff: last.diff }

Check warning on line 27 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:27: Survived StringLiteral mutant (replacement: ""). See the job summary for the complete list and resolution guidance.
}
type FileRevision = ReturnType<typeof fileRevision>
const isCurrentRevision = (cached: FileRevision | undefined, revision: FileRevision) =>

Check warning on line 30 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:30: Survived ArrowFunction mutant (replacement: () => undefined). See the job summary for the complete list and resolution guidance.
cached?.key === revision.key && cached.diff === revision.diff

Check warning on line 31 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:31: Survived ConditionalExpression mutant (replacement: true). See the job summary for the complete list and resolution guidance.

const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChangesPanelProps) => {
const { t } = useAppTranslation()
const [panelExpanded, setPanelExpanded] = useState(false)
const [expandedPaths, setExpandedPaths] = useState<Set<string>>(new Set())
const [finalContentByPath, setFinalContentByPath] = useState<Record<string, string | null>>({})
const pendingPathsRef = useRef<Set<string>>(new Set())
const [finalContentByPath, setFinalContentByPath] = useState<
Record<string, FileRevision & { content: string | null }>
>({})
const pendingPathsRef = useRef(new Map<string, FileRevision & { taskId?: string }>())
// The extension omits `originalContent` from the messages it posts; it is requested when a row is expanded.
const [originalContentByKey, setOriginalContentByKey] = useState<Record<string, string | null>>({})
// In-flight requests, keyed by task and message. Deliberately not reset with the caches below: a request cannot
Expand All @@ -37,12 +48,12 @@
// the request effect must not act on rows expanded under the previous task.
const expandedTaskIdRef = useRef(taskId)

// Reset expanded file rows and final content cache when the messages change
// Streaming replaces the messages array repeatedly. Keep the reader's expanded
// rows and scroll position until the task itself changes.
useEffect(() => {
setExpandedPaths(new Set())
setFinalContentByPath({})
pendingPathsRef.current = new Set()
}, [clineMessages, taskId])
}, [taskId])
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// Originals are keyed by message id, which is stable across message updates, so they only reset per task
useEffect(() => {
Expand Down Expand Up @@ -94,13 +105,14 @@
const entries = byPath.get(path)
if (!entries?.length) continue
const first = entries[0]
const revision = fileRevision(entries)
const lookupPath = path.startsWith("./") ? path.slice(2) : path
if (
first.hasOriginalContent &&
!(lookupPath in finalContentByPath) &&
!isCurrentRevision(finalContentByPath[lookupPath], revision) &&
!pendingPathsRef.current.has(lookupPath)
) {
pendingPathsRef.current.add(lookupPath)
pendingPathsRef.current.set(lookupPath, { ...revision, taskId })
vscode.postMessage({ type: "readFileContent", text: lookupPath })
}
const requestKey = `${taskId ?? ""}|${originalKey(first)}`
Expand All @@ -127,8 +139,14 @@
const message: ExtensionMessage = event.data
if (message.type === "fileContent" && message.fileContent?.path != null) {
const fc = message.fileContent
const request = pendingPathsRef.current.get(fc.path)
if (!request) return
pendingPathsRef.current.delete(fc.path)
setFinalContentByPath((prev) => ({ ...prev, [fc.path]: fc.content ?? null }))
setFinalContentByPath((prev) =>
request.taskId === taskId

Check warning on line 146 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:146: Survived ConditionalExpression mutant (replacement: true). See the job summary for the complete list and resolution guidance.
? { ...prev, [fc.path]: { ...request, content: fc.content ?? null } }
: { ...prev },

Check warning on line 148 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:148: NoCoverage ObjectLiteral mutant (replacement: {}). See the job summary for the complete list and resolution guidance.
)
} else if (message.type === "originalContent" && message.originalContentInfo) {
const { taskId: responseTaskId, content, ...id } = message.originalContentInfo
const key = originalKey(id)
Expand All @@ -147,7 +165,7 @@
const fileCount = byPath.size

return (
<Collapsible open={panelExpanded} onOpenChange={setPanelExpanded} className={cn("px-3", className)}>
<Collapsible open={panelExpanded} onOpenChange={setPanelExpanded} className={cn("px-3 shrink-0", className)}>

Check warning on line 168 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:168: Survived StringLiteral mutant (replacement: ""). See the job summary for the complete list and resolution guidance.
<CollapsibleTrigger
className={cn(
"flex items-center gap-2 w-full py-2 rounded-md text-left text-vscode-foreground",
Expand Down Expand Up @@ -178,13 +196,20 @@
</div>
) : null}
</CollapsibleTrigger>
<CollapsibleContent>
<CollapsibleContent
data-testid="file-changes-list"
className="max-h-[40vh] overflow-y-auto overscroll-contain"
tabIndex={0}
aria-label={t("chat:fileChangesInConversation.header", { count: fileCount })}>

Check warning on line 203 in webview-ui/src/components/chat/FileChangesPanel.tsx

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/FileChangesPanel.tsx:203: 2 mutation test gaps; example: Survived StringLiteral mutant (replacement: ""). See the job summary for the complete list and resolution guidance.
<div className="flex flex-col gap-1 pb-2 pl-6">
{Array.from(byPath.entries()).map(([path, entries]) => {
const originalContent =
entries[0].originalContent ?? originalContentByKey[originalKey(entries[0])] ?? undefined
const lookupPath = path.startsWith("./") ? path.slice(2) : path
const finalContent = finalContentByPath[lookupPath]
const cached = finalContentByPath[lookupPath]
const finalContent = isCurrentRevision(cached, fileRevision(entries))
? cached?.content
: undefined
const hasMergedDiff =
originalContent !== undefined && finalContent != null && finalContent !== ""
const displayDiff = hasMergedDiff
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading