-
Notifications
You must be signed in to change notification settings - Fork 412
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 initializer to LabeledExprSyntax
that automatically adds a colon if the label exists
#1984
Comments
I would love to tackle this after the |
I assigned the issue to you. Let me know if you have any questions. |
I started looking into it. The first two PRs I was playing on easy, but for this one, I'll stop and read the documentation on the basic building blocks of swift-syntax — so that one will take a few days. I hope to put together the first pull request with just the How does that sound, @ahoppen? |
Sounds good to me 👍🏽 |
Found a little bug somewhere in swift-markdown or swift-docc: swiftlang/swift-docc#685 I'm continuing to work on this — hope to have some focus time on Sunday to figure out where the definitions are for the generated code, and how to edit them. Taking it slow to not cut too many corners. |
@ahoppen, by handwritten, do you suggest that we add an extension for |
Oh, interesting. This seems to be related to
Take your time. Thanks for contributing to swift-syntax in the first place.
Exactly. We do already have similar convenience initializers in the SwiftSyntaxBuilder module. I would suggest that we create a similar file in the SwiftSyntax module. |
Ah, I missed them — there's |
@ahoppen, quick gut check.
Is there another scenario I'm missing with it? |
Also, here's what I'm doing to get the other nodes with optional colon:
I think a good next step is for me to post a list that I'll get and get a thumbs up from you and @Matejkob ;) |
I just checked and But I agree with you that the equal sign should be added automatically if
The plan sounds good 👍🏽 I’m curious how much else you find that’s not a colon. |
That's because I'm dumb, and I actually implemented the convenience init and then ran that test 🤦🏼 public func testClosureCaptureSyntaxConvenienceInitWithEqual() {
let noNameClosure = ClosureCaptureSyntax(name: "test", expression: ExprSyntax("123"))
XCTAssertEqual(noNameClosure.formatted().description, "[test = 123]")
} So, you're right, it just picked up my convenience init instead of the generated one. I'll roll that into a little PR of its own.
I love how you're pushing me to actually think and learn more, instead of just doing some "creative search and replace" ;) |
**Summary** This adds a convenience init to ClosureCaptureSyntax that adds equal token if the provided `name` is not nil. It's supposed to be used by developers, so it omits the unexpected tokens. Related: swiftlang#1984
**Summary** This adds a convenience init to ClosureCaptureSyntax that adds equal token if the provided `name` is not nil. It's supposed to be used by developers, so it omits the unexpected tokens. Related: swiftlang#1984
Pushed up #2127, and realized that we could probably make this work with CodeGeneration. For some
I think we can express these rules in How does that look? As long as I've got the general idea right, I'll tinker with Node in CodeGeneration and see if I can get it to work. |
If we can express this in |
@ahoppen I fully agree. I've played around with CodeGeneration and drafted how the change could look like. Basically:
I haven't looked into how to also generate tests for this, but overall seems doable at my exposure level. I agree that the next step is to write down the list of SyntaxNodes and the rules that we want to apply, and then see if that simple scheme will work. I should have the list and a draft PR in a couple of days. |
The approach sounds good in general. I’m looking forward to a PR. |
Also, if we are generating these initializers, we don’t need to write a test case for every one since if one of them works, we assume that all the others should work as well. |
**Summary** This adds a convenience init to ClosureCaptureSyntax that adds equal token if the provided `name` is not nil. It's supposed to be used by developers, so it omits the unexpected tokens. Related: swiftlang#1984
Currently, if you do the following
you get
label MyType
, which is surprising because the colon is missing and you would expect the colon to be present if there is a first name of the enum case parameter.To fix this, we should add a hand-written initializer of
EnumCaseParameterSyntax
, which takes a non-optionalfirstName
and automatically adds a colon, because it knows that thefirstName
exists. The above call would pick that overload and thus add a colon.And the same strategy can also be applied
ClosureCaptureSyntax.equal
AttributeSyntax
MacroExpansionDeclSyntax
ClosureCaptureModifierSyntax
FunctionCallExprSyntax
FreestandingMacroExpansionSyntax
rdar://107794232
The text was updated successfully, but these errors were encountered: