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
This commit is contained in:
Taylor Mullen
2025-05-15 23:51:53 -07:00
committed by N. Taylor Mullen
parent dce7d2c4f7
commit 968e09f0b5
17 changed files with 504 additions and 28 deletions

View File

@@ -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();