Fix(diff): Hide whitespace changes in diffs with content changes
- Updated the diff generation in `edit.ts` and `write-file.ts` to include the `ignoreWhitespace: true` option. - This ensures that whitespace-only changes are not highlighted in the diff output when there are other content modifications, making the diffs cleaner and easier to review. - Extract default diffing options into single source of truth. Fixes https://github.com/google-gemini/gemini-cli/issues/548
This commit is contained in:
parent
8440b971f5
commit
70d469ccd3
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as Diff from 'diff';
|
||||||
|
|
||||||
|
export const DEFAULT_DIFF_OPTIONS: Diff.PatchOptions = {
|
||||||
|
context: 3,
|
||||||
|
ignoreWhitespace: true,
|
||||||
|
};
|
|
@ -22,6 +22,7 @@ import { ReadFileTool } from './read-file.js';
|
||||||
import { GeminiClient } from '../core/client.js';
|
import { GeminiClient } from '../core/client.js';
|
||||||
import { Config } from '../config/config.js';
|
import { Config } from '../config/config.js';
|
||||||
import { ensureCorrectEdit } from '../utils/editCorrector.js';
|
import { ensureCorrectEdit } from '../utils/editCorrector.js';
|
||||||
|
import { DEFAULT_DIFF_OPTIONS } from './diffOptions.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters for the Edit tool
|
* Parameters for the Edit tool
|
||||||
|
@ -326,7 +327,7 @@ Expectation for parameters:
|
||||||
newContent,
|
newContent,
|
||||||
'Current',
|
'Current',
|
||||||
'Proposed',
|
'Proposed',
|
||||||
{ context: 3 },
|
DEFAULT_DIFF_OPTIONS,
|
||||||
);
|
);
|
||||||
const confirmationDetails: ToolEditConfirmationDetails = {
|
const confirmationDetails: ToolEditConfirmationDetails = {
|
||||||
type: 'edit',
|
type: 'edit',
|
||||||
|
@ -408,7 +409,7 @@ Expectation for parameters:
|
||||||
editData.newContent,
|
editData.newContent,
|
||||||
'Current',
|
'Current',
|
||||||
'Proposed',
|
'Proposed',
|
||||||
{ context: 3 },
|
DEFAULT_DIFF_OPTIONS,
|
||||||
);
|
);
|
||||||
displayResult = { fileDiff, fileName };
|
displayResult = { fileDiff, fileName };
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import {
|
||||||
ensureCorrectFileContent,
|
ensureCorrectFileContent,
|
||||||
} from '../utils/editCorrector.js';
|
} from '../utils/editCorrector.js';
|
||||||
import { GeminiClient } from '../core/client.js';
|
import { GeminiClient } from '../core/client.js';
|
||||||
|
import { DEFAULT_DIFF_OPTIONS } from './diffOptions.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters for the WriteFile tool
|
* Parameters for the WriteFile tool
|
||||||
|
@ -173,7 +174,7 @@ export class WriteFileTool extends BaseTool<WriteFileToolParams, ToolResult> {
|
||||||
correctedContent, // Content after potential correction
|
correctedContent, // Content after potential correction
|
||||||
'Current',
|
'Current',
|
||||||
'Proposed',
|
'Proposed',
|
||||||
{ context: 3 },
|
DEFAULT_DIFF_OPTIONS,
|
||||||
);
|
);
|
||||||
|
|
||||||
const confirmationDetails: ToolEditConfirmationDetails = {
|
const confirmationDetails: ToolEditConfirmationDetails = {
|
||||||
|
@ -251,7 +252,7 @@ export class WriteFileTool extends BaseTool<WriteFileToolParams, ToolResult> {
|
||||||
fileContent,
|
fileContent,
|
||||||
'Original',
|
'Original',
|
||||||
'Written',
|
'Written',
|
||||||
{ context: 3 },
|
DEFAULT_DIFF_OPTIONS,
|
||||||
);
|
);
|
||||||
|
|
||||||
const llmSuccessMessage = isNewFile
|
const llmSuccessMessage = isNewFile
|
||||||
|
|
Loading…
Reference in New Issue