Skip to content

Introduce FixIt.Change.replaceText #3030

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

Merged
merged 3 commits into from
Mar 29, 2025

Conversation

DougGregor
Copy link
Member

Introduce a new case to FixIt.Change to express an unstructured edit, which replaces some range of source text (in a given file) with some other source text. This is needed for some edits that aren't easily mapped to the syntax tree, or when coming from other tools (such as the compiler) that don't express these fixes in terms of syntax in the first place.

Introduce a new case to FixIt.Change to express an unstructured edit,
which replaces some range of source text (in a given file) with some
other source text. This is needed for some edits that aren't easily
mapped to the syntax tree, or when coming from other tools (such as
the compiler) that don't express these fixes in terms of syntax in the
first place.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/swift#80365

@swift-ci please test

@DougGregor
Copy link
Member Author

/// this case provides a fallback for textual replacement that ignores
/// syntactic structure. After applying a textual replacement, there is no
/// way to get back to a syntax tree without reparsing.
case textualReplacement(replacementRange: Range<AbsolutePosition>, sourceFile: SourceFileSyntax, newText: String)
Copy link
Member

@ahoppen ahoppen Mar 28, 2025

Choose a reason for hiding this comment

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

To match the other cases, this should start with replace as well. I would suggest replaceText.

Suggested change
case textualReplacement(replacementRange: Range<AbsolutePosition>, sourceFile: SourceFileSyntax, newText: String)
case replaceText(range: Range<AbsolutePosition>, with: String, in: SourceFileSyntax)

Rename according to the discussion. Additionally, only require a Syntax node
(not a SourceFileSyntax) as the place we're rewriting from.
@DougGregor
Copy link
Member Author

swiftlang/swift#80376

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/swift#80376

@swift-ci please test Windows

@DougGregor DougGregor changed the title Introduce FixIt.Change.textualReplacement Introduce FixIt.Change.replaceText Mar 29, 2025
@DougGregor DougGregor merged commit 94681ba into swiftlang:main Mar 29, 2025
24 checks passed
@DougGregor DougGregor deleted the fixit-textual-replacement branch March 29, 2025 04:41
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