Skip to content

Conversation

@connor4312
Copy link
Member

  • Minimize identical content in text edits to avoid potential conflicts in context
  • Explicitly error any edits that still fail rather than garbling the file

Closes microsoft/vscode#277154

- Minimize identical content in text edits to avoid potential conflicts in context
- Explicitly error any edits that still fail rather than garbling the file

Closes microsoft/vscode#277154
Copilot AI review requested due to automatic review settings November 14, 2025 20:12
@connor4312 connor4312 enabled auto-merge November 14, 2025 20:12
@connor4312 connor4312 self-assigned this Nov 14, 2025
Copilot finished reviewing on behalf of connor4312 November 14, 2025 20:14
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 14, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical issue where the multi_replace_string_in_file tool could garble files when multiple replacements had overlapping ranges. The fix introduces two main improvements: (1) minimizing edits to preserve identical content between old and new strings, reducing the likelihood of conflicts, and (2) explicitly detecting and reporting conflicting edits rather than silently producing incorrect results.

Key changes:

  • Edit minimization: All matching strategies now calculate and preserve identical leading/trailing content
  • Conflict detection: New validation in abstractReplaceStringTool.tsx detects and errors on overlapping edits
  • Comprehensive test coverage: Extensive tests added for whitespace-flexible, similarity, and edit minimization strategies

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/extension/tools/node/editFileToolUtils.tsx Core implementation of edit minimization logic across all matching strategies; added helper functions getIdenticalLines and getIdenticalChars
src/extension/tools/node/abstractReplaceStringTool.tsx Added conflict detection via _errorConflictingEdits method to validate edits don't overlap
src/extension/tools/node/test/editFileToolUtils.spec.ts Added comprehensive test coverage for whitespace-flexible matching, similarity matching, and edit minimization
src/extension/tools/node/test/multiReplaceStringTool.spec.tsx Changed test from skip to only; added validation for conflict error message

Tyriar
Tyriar previously approved these changes Nov 14, 2025
@connor4312
Copy link
Member Author

Ended up fixing some other edge cases in this PR too, should help tidy up edits 💪

@connor4312 connor4312 added this pull request to the merge queue Nov 15, 2025
Merged via the queue into main with commit 5f8b3a7 Nov 15, 2025
16 checks passed
@connor4312 connor4312 deleted the connor4312/multi-sr-conflicting branch November 15, 2025 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The multi_replace_string_in_file trashed my file due to overlapping replacements

4 participants