fix(core): correct ellipsis logic in EditTool getDescription()#28105
fix(core): correct ellipsis logic in EditTool getDescription()#28105Megashubham wants to merge 3 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
📊 PR Size: size/M
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
|
@googlebot I signed it! |
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
|
/gemini summary |
Summary of ChangesThis pull request addresses a display bug in the EditTool description generation where the ellipsis suffix was incorrectly determined based on the total string length instead of the visible snippet length. The changes ensure that the UI accurately indicates when content is truncated or spans multiple lines, improving the clarity of edit descriptions. Highlights
Activity
|
04fdac1 to
37796db
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the getDescription method in EditToolInvocation to correctly append an ellipsis when truncating multi-line strings, even if the first line is short. It also adds comprehensive unit tests to verify this behavior under various scenarios. The review feedback highlights a performance concern where using split('\n') on large files can cause high memory usage, and suggests an optimized approach using indexOf('\n') along with proper handling of multi-byte Unicode characters.
37796db to
e530737
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the snippet generation logic in packages/core/src/tools/edit.ts to handle multi-line strings and multi-byte characters, and adds comprehensive unit tests in packages/core/src/tools/edit.test.ts. The review feedback correctly identifies a potential issue with Windows-style line endings (\r\n), where the carriage return (\r) is retained in the extracted first line and can cause rendering issues in terminal environments. A code suggestion is provided to normalize line endings before processing.
The description snippet for old_string and new_string was using the total string length to decide whether to append '...' instead of checking the first-line length that was actually being displayed. This caused two issues: - Multi-line strings with a short first line (< 30 chars) would not show '...' even though the edit description was only showing the first line, hiding that the edit spans multiple lines. - The check was inconsistent: substring(0, 30) was applied on the first line, but the length guard was on the entire string. Fix by extracting the first line into a variable and checking: 1. Whether the first line itself exceeds 30 characters (truncated by substring), OR 2. Whether the full string is multi-line (\n present), indicating more content exists beyond what is shown. Added unit tests to cover all cases: new file, short single-line, multi-line with short first line, long first line, and no-op edits.
e530737 to
91bd882
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the snippet generation logic in EditToolInvocation.getDescription to normalize line endings and correctly handle multi-byte characters, accompanied by comprehensive unit tests. The review feedback highlights a potential performance and memory issue where calling Array.from on extremely long lines could cause OOM crashes, and provides an optimized suggestion to check the string length before array conversion.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive unit tests for the getDescription method in edit.test.ts and refactors the snippet extraction logic in edit.ts to handle line-ending normalization and truncation. The reviewer provided valuable feedback on simplifying the getSnippet helper function by using Array.from() directly on the first line, which ensures safe truncation of multi-byte Unicode characters without splitting them.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
6bddbc8 to
8f125c6
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the snippet generation logic in EditToolInvocation.getDescription to normalize CRLF line endings and safely handle multi-byte Unicode characters when truncating strings, accompanied by comprehensive unit tests. Feedback suggests optimizing the truncation logic by using Intl.Segmenter to lazily evaluate grapheme clusters up to the 30-character limit, preventing potential performance and memory issues on extremely large single-line inputs.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function getSnippet in packages/core/src/tools/edit.ts to safely extract and truncate snippets of old and new strings using Intl.Segmenter for grapheme-safe truncation, along with corresponding unit tests in packages/core/src/tools/edit.test.ts. However, a logical bug was identified in the truncation condition where chars.length is capped at 30 before checking if it exceeds 30, making the truncation block unreachable and causing tests for long lines to fail. A refactored implementation using array slicing was suggested to resolve this issue.
ca7fa59 to
f011559
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the snippet generation logic in EditToolInvocation.getDescription to use Intl.Segmenter for grapheme-aware truncation and adds comprehensive unit tests. The reviewer recommends optimizing the getSnippet helper to process large inputs lazily, preventing potential performance degradation or out-of-memory errors from eager string replacement and segmentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
f011559 to
accb71e
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the snippet generation logic in packages/core/src/tools/edit.ts to use Intl.Segmenter for safely segmenting the first line of the edit strings up to 30 characters, handling multi-line strings, and stripping trailing carriage returns (\r). It also adds comprehensive unit tests in packages/core/src/tools/edit.test.ts to verify these behaviors under various scenarios. There are no review comments, and I have no feedback to provide.
|
can you check once :P |
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
|
This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
Fixes a subtle display bug in
EditToolInvocation.getDescription()where the ellipsis (...) suffix in the edit description snippet was incorrectly computed.The Bug
The code extracts the first line of
old_stringvia.split('\n')[0]and applies.substring(0, 30)to it. However, the ellipsis decision was based onthis.params.old_string.length > 30- the length of the entire string, not the first line.Example:
old_string = "function foo() {\n return 1;\n}"(30 chars total)"function foo() {"is only 17 chars - correctly displayedold_string.length > 30->false-> no...even though the edit spans multiple lines!The Fix
The fix appends
...when: (1) the first line itself exceeds 30 characters (truncated bysubstring), or (2) the full string contains newlines (multi-line), so more content exists beyond the snippet. Same fix is applied symmetrically tonew_string.Tests
Added 5 new unit tests in
edit.test.tscovering all cases: new file (emptyold_string) - no ellipsis; short single-line strings - no ellipsis; multi-line string with short first line - shows...(the regression case); long first line (> 30 chars) - shows...; sameold_stringandnew_string- "No file changes" message.All 67 tests pass. TypeScript typecheck passes. ESLint + Prettier pass.
This fix has already been implemented, the tests pass, and it's ready for review.