-
Couldn't load subscription status.
- Fork 32
Fix application of fix-its replacing parent instead of first child #16
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
Fix application of fix-its replacing parent instead of first child #16
Conversation
This pulls in the latest `FixItApplier` from swift-syntax `main` (d647052), which is now String-based. Fixes pointfreeco#15.
4d550d8 to
fdf08ac
Compare
|
Also for consideration, see a disfavored alternative approach: fix-it-applier-compare-kind. While interesting, I think it ultimately reinforces this PR's solution. In this alternative, I'd independently arrived at the same simple solution that #12 initially had but removed before merging. However, because |
| } | ||
| } | ||
|
|
||
| // From: https://github.com/apple/swift-syntax/blob/d647052/Sources/SwiftSyntaxMacrosTestSupport/Assertions.swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of inlining these in the library, what do you think of putting it in a file in the SwiftSyntax directory alongside SourceEdit, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'm happy to do that. I didn't do so initially because the upstream extensions are fileprivate and kept close to the asserts that use them. Plus, these two extensions are just a small parts of their larger upstream file, and I think files from upstream have so far been pulled in wholesale with minimal alterations.
Here are the upstream extensions' signatures from SwiftSyntax's SwiftSyntaxMacrosTestSupport/Assertions.swift:
extension FixIt.Change {
fileprivate func edit(
in expansionContext: BasicMacroExpansionContext
) -> SourceEdit {
…
}
}extension BasicMacroExpansionContext {
fileprivate func position(
of position: AbsolutePosition,
anchoredAt node: some SyntaxProtocol
) -> AbsolutePosition {
…
}
}I think it'd be okay to make the extensions internal instead of fileprivate. Here are some options:
- Since
BasicMacroExpansionContextis common between the two extensions, make the extensionsinternaland add them to a new file:Sources/SwiftSyntax/SourceEditMacroExpansion.swift. - Make the extensions
internaland them directly toSources/SwiftSyntax/SourceEdit.swift. - If you'd rather leave them in
AssertMacro.swiftasfileprivate, I can move them to the end of the file.
For me to move forward, feel free to pick one of these ideas or throw in another that you think might work better. Looking forward to your input!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just one small thing. Wanna tackle it before we merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've convinced me that moving the methods is probably not worth it 😄
This fixes #15 by pulling in the latest
FixItApplierfrom swift-syntaxmain(d647052), which is now String-based.Note:
FixItApplierhas undergone a complete rework in swift-syntaxmain. It’s nowString-based rather thanSyntaxRewriter-based. (It’s publicly accessible but not exposed as a product within the underscored_SwiftSyntaxTestSupportmodule, an “internal helper target”.)FixItApplier.applyFixesfunction isn’t needed by swift-macro-testing, and omitting it allows these two extensions onFixItto be omitted.SwiftSyntax/SourceEditis public but hasn't been released, so eventually it can be removed from swift-macro-testing.