diff options
| author | Taylor Mullen <[email protected]> | 2025-05-15 23:51:53 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-16 10:13:13 -0700 |
| commit | 968e09f0b50d17f7c591baa977666b991a1e59b7 (patch) | |
| tree | e7d7e6ea7211003074a6b967b3736457972fc927 /packages/cli/src/ui/hooks | |
| parent | dce7d2c4f799d537b2be00fe28e2b872550fc77d (diff) | |
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
Diffstat (limited to 'packages/cli/src/ui/hooks')
| -rw-r--r-- | packages/cli/src/ui/hooks/atCommandProcessor.ts | 6 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useCompletion.ts | 12 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useGeminiStream.ts | 3 |
3 files changed, 14 insertions, 7 deletions
diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.ts b/packages/cli/src/ui/hooks/atCommandProcessor.ts index e0cf65c5..e2934840 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.ts @@ -154,7 +154,9 @@ export async function handleAtCommand({ if (isNodeError(error) && error.code === 'ENOENT') { onDebugMessage(`Path not found, proceeding with original: ${pathSpec}`); } else { - console.error(`Error stating path ${pathPart}:`, error); + console.error( + `Error stating path ${pathPart}: ${getErrorMessage(error)}`, + ); onDebugMessage( `Error stating path, proceeding with original: ${pathSpec}`, ); @@ -200,7 +202,7 @@ export async function handleAtCommand({ ); return { processedQuery, shouldProceed: true }; - } catch (error) { + } catch (error: unknown) { // Handle errors during tool execution toolCallDisplay = { callId: `client-read-${userMessageTimestamp}`, diff --git a/packages/cli/src/ui/hooks/useCompletion.ts b/packages/cli/src/ui/hooks/useCompletion.ts index 622dc4c4..9c0c2db1 100644 --- a/packages/cli/src/ui/hooks/useCompletion.ts +++ b/packages/cli/src/ui/hooks/useCompletion.ts @@ -7,7 +7,12 @@ import { useState, useEffect, useCallback } from 'react'; import * as fs from 'fs/promises'; import * as path from 'path'; -import { isNodeError, escapePath, unescapePath } from '@gemini-code/server'; +import { + isNodeError, + escapePath, + unescapePath, + getErrorMessage, +} from '@gemini-code/server'; import { MAX_SUGGESTIONS_TO_SHOW, Suggestion, @@ -202,7 +207,7 @@ export function useCompletion( setActiveSuggestionIndex(filteredSuggestions.length > 0 ? 0 : -1); setVisibleStartIndex(0); } - } catch (error) { + } catch (error: unknown) { if (isNodeError(error) && error.code === 'ENOENT') { // Directory doesn't exist, likely mid-typing, clear suggestions if (isMounted) { @@ -211,8 +216,7 @@ export function useCompletion( } } else { console.error( - `Error fetching completion suggestions for ${baseDirAbsolute}:`, - error, + `Error fetching completion suggestions for ${baseDirAbsolute}: ${getErrorMessage(error)}`, ); if (isMounted) { resetCompletionState(); diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index a9aa8d54..29ce313d 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -326,6 +326,7 @@ export const useGeminiStream = ( if ('fileDiff' in originalDetails) { resultDisplay = { fileDiff: (originalDetails as ToolEditConfirmationDetails).fileDiff, + fileName: (originalDetails as ToolEditConfirmationDetails).fileName, }; } else { resultDisplay = `~~${(originalDetails as ToolExecuteConfirmationDetails).command}~~`; @@ -590,7 +591,7 @@ export const useGeminiStream = ( addItem( { type: MessageType.ERROR, - text: `[Stream Error: ${getErrorMessage(error)}]`, + text: `[Stream Error: ${getErrorMessage(error) || 'Unknown error'}]`, }, userMessageTimestamp, ); |
