Skip to content

Make RenameLocation unique#2607

Open
DeeSee wants to merge 1 commit intoswiftlang:mainfrom
DeeSee:fix-duplicate-rename-edits
Open

Make RenameLocation unique#2607
DeeSee wants to merge 1 commit intoswiftlang:mainfrom
DeeSee:fix-duplicate-rename-edits

Conversation

@DeeSee
Copy link
Copy Markdown

@DeeSee DeeSee commented Apr 13, 2026

Summary

When a file is indexed by multiple compilation units (e.g. multiple targets in a build system compile or import the same source file), index.occurrences(ofUSR:roles:) returns one entry per unit for the same source position. These duplicate RenameLocations produce overlapping TextEdits in the WorkspaceEdit, which editors reject — VS Code shows "Rename failed to apply edits" with no further detail.

Changes

  • Changed locationsByFile to collect rename locations in a Set<RenameLocation> instead of [RenameLocation], effectively making duplicates impossible.
  • Made RenameLocation and RenameLocation.Usage conform to Hashable so they can be stored in a Set.
  • Sort the set into an array before passing to editsToRename, since the downstream API expects [RenameLocation] and some callers depend on ordering.

Test

  • I've added a test case that simulates the issue: it compiles single source file twice with different compilation conditions and then checks that rename doesn't produce duplicate edits. I've verified that this test fails if I rollback the fix.

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.

2 participants