feat(core): enhance EditTool with intelligent indentation rebasing#19178
feat(core): enhance EditTool with intelligent indentation rebasing#19178Thomas-Shephard wants to merge 5 commits intogoogle-gemini:mainfrom
Conversation
- Implement rebaseIndentation and handleTrailingSpaces utilities. - Integrate indentation rebasing into exact, flexible, and regex matching. - Preserve inline suffixes (comments, etc.) during multi-line replacements. - Add comprehensive tests for whitespace-only and multi-line rebasing. Relates to google-gemini#19177
Summary of ChangesHello @Thomas-Shephard, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the EditTool's ability to apply code modifications gracefully. It introduces intelligent indentation rebasing and trailing whitespace management, ensuring that AI-generated code snippets or replacements seamlessly conform to the existing file's formatting and style, thereby improving the overall quality and consistency of automated code changes. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces intelligent indentation rebasing and trailing whitespace handling to the EditTool, which is a great enhancement for ensuring AI-generated code edits match the existing file's style. The changes are extensive, touching all three replacement strategies (exact, flexible, and regex) and are backed by a comprehensive new set of tests. However, I found a critical issue in the new implementation of calculateExactReplacement that could lead to incorrect results when performing multiple replacements. My review includes a detailed explanation and a suggested fix for this issue.
6f8cea7 to
90bf646
Compare
…d non-overlapping matching - Implement rebaseIndentation and handleTrailingSpaces utilities. - Refactor calculateExactReplacement for non-overlapping 'replaceAll' behavior using immutable original content. - Integrate indentation rebasing into all matching strategies (exact, flexible, regex). - Preserve inline suffixes and respect multi-line indentation shifts. - Add comprehensive test suite covering rebasing edge cases and overlapping matches. Closes google-gemini#19177
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces intelligent indentation rebasing and trailing whitespace handling to the EditTool. While these are valuable enhancements, a critical issue has been identified in the calculateExactReplacement function where the new indentation rebasing logic fails for multiple occurrences of a multi-line search string, potentially leading to inconsistent formatting.
- Fix indentation rebasing consistency for multiple multi-line occurrences. - Ensure line prefix safety using lastOffset validation. - Add regression test for consistent multi-line rebasing. - Clean up code formatting and unused expressions.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the EditTool by introducing intelligent indentation rebasing and improving whitespace handling through new rebaseIndentation and handleTrailingSpaces utilities, making the tool more robust in preserving file styling. While the extensive test suite is excellent, a potential issue was identified in the suffix handling logic within calculateExactReplacement that could lead to incorrect indentation. Overall, this is a great improvement to the tool's capabilities.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the EditTool by introducing intelligent indentation rebasing and sophisticated handling of trailing whitespace and inline suffixes. The new rebaseIndentation and handleTrailingSpaces utilities are well-designed and have been thoughtfully integrated into all three replacement strategies (exact, flexible, and regex), making code replacements much more robust and style-aware. The logic for preserving suffixes is a great addition that will prevent data loss in common editing scenarios. The accompanying tests are comprehensive and cover a wide range of edge cases, which gives high confidence in the correctness of these complex changes. Overall, this is an excellent improvement to the tool's capabilities.
Summary
This PR enhances the EditTool by implementing intelligent indentation rebasing and trailing whitespace handling. These improvements ensure that code replacements integrate seamlessly with the existing file's style, even when the AI-proposed code has different indentation levels.
Details
Related Issues
Closes #19177
How to Validate
Run the tests:
bash
npm test -w @google/gemini-cli-core -- src/tools/edit.test.ts
All 52 tests should pass.
Pre-Merge Checklist