-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix/issue 2325 bracket duplication #5573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/issue 2325 bracket duplication #5573
Conversation
| const matchedLines = resultLines.slice(matchIndex, matchIndex + searchLines.length) | ||
|
|
||
| // Check for potential bracket duplication | ||
| let extendReplacement = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the bracket duplication logic within applyDiff, the boolean variable 'extendReplacement' is set to true when a matching extra closing bracket is found, but it isn’t used later (only additionalLinesToReplace is used). Consider removing 'extendReplacement' to simplify the code.
|
Thanks for working on this @MuriloFP. Looking at the implementation, I still have concerns similar to what I mentioned in PR #3997 and later reiterated here. We're adding processing logic to every search/replace operation to handle a quirk that mostly affects certain models like DeepSeek. I think we should be cautious about introducing special cases or guardrails for every model behavior. In cases like this, we might be better off improving the tool prompt or tweaking how it's described, rather than baking in logic changes that increase overall complexity. I personally haven't seen this issue recently since that PR was opened so it seems like it mostly affected the old deepseek v3. I'll close it for now, we can discuss in the issue if this is still happening, if not then we can close the issue. |
Related GitHub Issue
Closes: #2325
Roo Code Task Context (Optional)
N/A
Description
This PR fixes a bug in the
apply_difftool where closing brackets were being duplicated when appending content before them. The issue occurred when::start_line:to target a specific lineKey implementation details:
isClosingBracketLine()to detect lines containing only closing brackets, andgetLastNonEmptyLine()to find the last non-empty line in contentapplyDiffmethod inMultiSearchReplaceDiffStrategyto detect when replacement content ends with a closing bracket that wasn't in the search},],),>) and accounts for whitespace variationsDesign choices:
Areas for review focus:
multi-search-replace.tsTest Procedure
Unit tests added:
To reproduce and verify:
cd src && npx vitest core/diff/strategies/__tests__/multi-search-replace.spec.tscd src && npx vitest core/diff/strategiesManual testing:
apply_difftool with a search that doesn't include a closing bracket but a replacement that does},],),>)Testing results:
Pre-Submission Checklist
Screenshots / Videos
N/A - No UI changes
Documentation Updates
Additional Notes
This fix only modifies internal backend logic with no user-facing strings or UI changes, so no translations were required.
Get in Touch
@MuriloFP
Important
Fixes bracket duplication in
applyDiffby extending replacement scope to include original closing bracket lines, with tests added for validation.applyDiffinmulti-search-replace.tsby extending replacement scope to include original closing bracket lines when necessary.},],),>) and accounts for whitespace variations.isClosingBracketLine()andgetLastNonEmptyLine()to assist in detecting and handling closing brackets.multi-search-replace.spec.tsto cover bracket duplication scenarios and edge cases.This description was created by
for 9e9dc3e. You can customize this summary. It will automatically update as commits are pushed.