From 968e09f0b50d17f7c591baa977666b991a1e59b7 Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Thu, 15 May 2025 23:51:53 -0700 Subject: fix: Ensure filename is available for diff rendering in write-file This commit resolves a bug where the `write-file` operation could fail to render content due to a missing filename. The fix involves: - Ensuring `fileName` is consistently passed to `DiffRenderer.tsx` through `ToolConfirmationMessage.tsx`, `ToolMessage.tsx`, and `useGeminiStream.ts`. - Modifying `edit.ts` and `write-file.ts` to include `fileName` in the `FileDiff` object. - Expanding the `FileDiff` interface in `tools.ts` to include `fileName`. Additionally, this commit enhances the diff rendering by: - Adding syntax highlighting based on file extension in `DiffRenderer.tsx`. - Adding more language mappings to `getLanguageFromExtension` in `DiffRenderer.tsx`. - Added lots of tests for all the above. Fixes https://b.corp.google.com/issues/418125982 --- .../src/ui/components/messages/DiffRenderer.tsx | 33 +++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'packages/cli/src/ui/components/messages/DiffRenderer.tsx') diff --git a/packages/cli/src/ui/components/messages/DiffRenderer.tsx b/packages/cli/src/ui/components/messages/DiffRenderer.tsx index a9afeca3..4baed3e8 100644 --- a/packages/cli/src/ui/components/messages/DiffRenderer.tsx +++ b/packages/cli/src/ui/components/messages/DiffRenderer.tsx @@ -105,6 +105,14 @@ export const DiffRenderer: React.FC = ({ const parsedLines = parseDiffWithLineNumbers(diffContent); + if (parsedLines.length === 0) { + return ( + + No changes detected. + + ); + } + // Check if the diff represents a new file (only additions and header lines) const isNewFile = parsedLines.every( (line) => @@ -233,16 +241,21 @@ const renderDiffContent = ( const getLanguageFromExtension = (extension: string): string | null => { const languageMap: { [key: string]: string } = { - '.js': 'javascript', - '.ts': 'typescript', - '.py': 'python', - '.json': 'json', - '.css': 'css', - '.html': 'html', - '.sh': 'bash', - '.md': 'markdown', - '.yaml': 'yaml', - '.yml': 'yaml', + js: 'javascript', + ts: 'typescript', + py: 'python', + json: 'json', + css: 'css', + html: 'html', + sh: 'bash', + md: 'markdown', + yaml: 'yaml', + yml: 'yaml', + txt: 'plaintext', + java: 'java', + c: 'c', + cpp: 'cpp', + rb: 'ruby', }; return languageMap[extension] || null; // Return null if extension not found }; -- cgit v1.2.3