fix: preserve indentation when applying code edits to Python files#11289
fix: preserve indentation when applying code edits to Python files#11289mvanhorn wants to merge 2 commits intocontinuedev:mainfrom
Conversation
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/edit/searchAndReplace/performReplace.ts">
<violation number="1" location="core/edit/searchAndReplace/performReplace.ts:58">
P2: First replacement line can remain unindented when `oldIndent` is non-empty, because fallback indentation adjustment only runs for `oldIndent === ""`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
When fallback matching strategies (trimmedMatch, whitespaceIgnoredMatch) find a match with different indentation than the LLM-provided old_string, the replacement new_string now has its indentation adjusted to match the actual indentation level in the file. This fixes incorrect indentation in Python code edits where the LLM provides unindented search/replace strings that match indented code blocks. Fixes continuedev#11282 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eplacements Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70b6b17 to
1cb68a5
Compare
|
Thanks to @luzhihaoTestingLab for reporting #11282 and to @cubic-dev-ai for catching the first-line indentation bug in review. What was wrong with the original approach (commit 3d257cd): The first version used What the new approach does (commit 1cb68a5): Replaced Added 5 test cases covering: basic indent adjustment, relative inner indentation preservation, tab vs space mismatch, exact match passthrough, and whitespace-ignored matching. |
Summary
trimmedMatch,whitespaceIgnoredMatch, etc.) to apply editsHow it works
adjustReplacementIndentation()compares the indentation of the file line at the match position against the leading indent of the LLM-providedold_string. If they differ:This handles tab/space mismatches, completely unindented LLM output, and deeply nested code blocks.
Test plan
old_stringmatching indented file content gets correct indentationwhitespaceIgnoredMatchwith differing internal whitespace works correctlyreplaceAllmode applies indentation adjustment per-matchFixes #11282
🤖 Generated with Claude Code