-
Notifications
You must be signed in to change notification settings - Fork 24
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
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 |
@@ -343,6 +349,57 @@ public func assertMacro( | |||
} | |||
} | |||
|
|||
// 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
BasicMacroExpansionContext
is common between the two extensions, make the extensionsinternal
and add them to a new file:Sources/SwiftSyntax/SourceEditMacroExpansion.swift
. - Make the extensions
internal
and them directly toSources/SwiftSyntax/SourceEdit.swift
. - If you'd rather leave them in
AssertMacro.swift
asfileprivate
, 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
FixItApplier
from swift-syntaxmain
(d647052), which is now String-based.Note:
FixItApplier
has 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_SwiftSyntaxTestSupport
module, an “internal helper target”.)FixItApplier.applyFixes
function isn’t needed by swift-macro-testing, and omitting it allows these two extensions onFixIt
to be omitted.SwiftSyntax/SourceEdit
is public but hasn't been released, so eventually it can be removed from swift-macro-testing.