-
Notifications
You must be signed in to change notification settings - Fork 439
Add result builder to decl blocks #305
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
Add result builder to decl blocks #305
Conversation
Cool. Thanks! And there’s no need to apologize, you are working on this in your free time after all. 😉 Let me know when the code is ready for review or if you have any questions. I just took a look at the code and it still appears to be in an incomplete state to me. |
f0a1d02
to
882014e
Compare
@kimdv What’s the state of this PR? Is it ready for review yet or still work in progress? |
882014e
to
28d9e2f
Compare
0527b7c
to
cad4f2b
Compare
@ahoppen I think it is in a state where it is ready for review. I have rebased with latest master |
cad4f2b
to
2a529d0
Compare
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 just looked through the changes and thought it was a little over-complicated to only generate the ExpressibleAs
protocols for types that are children of syntax collections – why not have them for all syntax nodes as they might also come in handy later? I also thought it was a bit of a shame that ExprBuildable
didn’t conform to ExpressibleAsExprBuildable
.
I couldn’t resist the temptation to play around with your design myself and think it’s easiest to just implement the ExpressibleAs
protocols in Buildables.swift.gyb
. That way we can also conform protocols like ExprBuildable
to their corresponding ExpressibleAs
protocols. I pushed my draft idea to ahoppen@d6d4f12. What do you think?
Sure we can generate for them all. Did that initially, but went away because I wouldn't introduce a lot of protocols that wasn't used. Will add them again.
My thought was just as we have a
So we should move everything from |
My thought process was that we are exposing these protocols publicly and it’s hard to explain why certain syntax kinds have
That’s a good point. I hadn’t thought of that. But I think that
I don’t have a strong preference for either of these options.
Not necessarily. I only did so to conform |
2a529d0
to
c82e22e
Compare
@ahoppen I have applied your suggestions 👍 I ended with adding |
c82e22e
to
eae4100
Compare
It wouldn’t have been the only one. |
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.
Looking very good to me. And the test cases really start to look like what I’ve always envisioned SwiftSyntaxBuilder
to look like 🤩
I’ve added some minor comments regarding the test cases inline.
Sources/SwiftSyntaxBuilder/StringLiteralExprConvenienceInitializers.swift
Outdated
Show resolved
Hide resolved
final class ExpressibleBuildablesTests: XCTestCase { | ||
func testExpressibleAsMemberDeclListItem() { | ||
let myStruct = StructDecl(identifier: "MyStruct", members: MemberDeclBlock(membersBuilder: { | ||
VariableDecl(.var, name: "myFirstVar", type: "Int") |
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.
This is really starting to look like you can generate real-world code with SwiftSyntaxBuilder
😍
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.
Yes! It look really good and it gets more and more clean to read! 🎉
} | ||
|
||
func testExpressibleAsCodeBlockItem() { | ||
let myCodeBlock = SourceFile(eofToken: SyntaxFactory.makeToken(.eof, presence: .present)) { |
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.
Not part of this PR but would it make sense to add
extension TokenSyntax {
static let eof = SyntaxFactory.makeToken(.eof, presence: .present)
}
So we could improve this to
let myCodeBlock = SourceFile(eofToken: SyntaxFactory.makeToken(.eof, presence: .present)) { | |
let myCodeBlock = SourceFile(eofToken: .eof) { |
And possibly try to remove the need to specify the eofToken
in the SourceFile
initializer altogether.
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.
Added in #314
e7f75c0
to
5c28acc
Compare
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.
Nice. Looks good to me. 🚀
@swift-ci Please test |
Build failed |
Build failed |
5c28acc
to
2228008
Compare
Rebased on latest master |
@swift-ci Please test |
Build failed |
Build failed |
Hi @ahoppen 👋
I have not forgotten you, just had a busy at work and then summer vacation!
And European Championship in football where Denmark did it very good ⚽️
But I'll get some time to look at somethings again.
From #291
This PR aims to A
MemberDeclBlock
should be directly creatable from aMemberDeclListBuilder
result builder. This would probably take some hardcoding ofMemberDeclBlock
in the convenience initializers where the initialization of aMemberDeclBlock
with aMemberDeclListBuilder
is another convenience added (besides the current ones of: syntax collection through result builder, tokens by string literals and defaulting of tokens)This will make it possible to make things like
I will next week start too look into it again, and catch up.
I will properly ask some questions