Skip to content

[SwiftIDEUtils] Normalize subtree edit offsets in FixItApplier - #3499

Open
Hokila wants to merge 1 commit into
swiftlang:mainfrom
Hokila:fix/fixit-applier-subtree-offsets
Open

Hokila wants to merge 1 commit into
swiftlang:mainfrom
Hokila:fix/fixit-applier-subtree-offsets

Conversation

@Hokila

@Hokila Hokila commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #2749
rdar://132355564

Applying diagnostics or edits to a subtree crashes in FixItApplier because edit ranges use root-file offsets while tree.description starts at offset zero.

FixItApplier.apply(edits:to:allowDuplicateInsertions:) now shifts edit offsets relative to tree.position.utf8Offset and drops individual edits outside tree. Also updates the doc comments and adds subtree tests in FixItApplierTests.swift.

@Hokila
Hokila force-pushed the fix/fixit-applier-subtree-offsets branch from feef316 to 7187cd5 Compare November 3, 2026 02:47
@Hokila
Hokila requested a review from nkcsgexi as a code owner November 3, 2026 02:47
@Hokila

Hokila commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

I self reviewed this PR and did some fix, @rintaro Could you take a look when you have a moment?

When applying diagnostics or edits to a subtree, edit ranges use absolute offsets from the root syntax tree while `tree.description` starts at offset zero.

Normalize edit offsets relative to `tree.position.utf8Offset`, reuse `replacementBytes`, and drop edits that fall outside the subtree range. Update `FixItApplier` doc comments and add subtree tests in `FixItApplierTests.swift`.

Resolves swiftlang#2749
rdar://132355564
@Hokila
Hokila force-pushed the fix/fixit-applier-subtree-offsets branch from 7187cd5 to 078e2a4 Compare November 13, 2026 07:57
@Hokila

Hokila commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main and trimmed the changes down to keep this PR simple.
This PR is ready for review.

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.

FixItApplier crash when generating diagnostics for whole tree but applying them to a subtree

1 participant