Skip to content

Improvements for do and related statements #511

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 1 commit into from
Aug 5, 2022
Merged

Conversation

evnik
Copy link
Contributor

@evnik evnik commented Jul 23, 2022

  • Leading/trailing spaces are updated to make statements well formatted
  • CatchClause convenience initializer that calculates spacing around the catch keyword
  • Test coverage for above changes

swiftlang/swift#60204

@@ -22,7 +22,7 @@ final class StructTests: XCTestCase {
let nestedStruct = StructDecl(
structKeyword: .struct.withLeadingTrivia(.docLineComment("/// A nested struct\n")),
identifier: "NestedStruct",
genericParameterClause: GenericParameterClause {
genericParameterClause: GenericParameterClause(rightAngleBracket: .rightAngle.withoutTrailingTrivia()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a temporary fix needed because of updates for the where keyword. I'm going to remove it with adjusting spaces around angle brackets in my next PR

Copy link
Member

Choose a reason for hiding this comment

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

I’m not sure how big the changes for the angle brackets are but feel free to include them in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not big, however I'd like to make a separate PR for them

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

The spacing changes look good to me. I’m not entirely convinced about CatchItems.

Comment on lines 12 to 15
CatchClause(CatchItems {
CatchItem(pattern: "Error1")
CatchItem(pattern: "Error2")
}) {
Copy link
Member

Choose a reason for hiding this comment

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

I’m not entirely convinced this is much better than the default implementation that’s already provided.

Suggested change
CatchClause(CatchItems {
CatchItem(pattern: "Error1")
CatchItem(pattern: "Error2")
}) {
CatchClause(catchItems: CatchItemList([
CatchItem(pattern: "Error1"),
CatchItem(pattern: "Error2")
])) {

Do you have some example where the result builder syntax is superior than using an array here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Result builder automatically inserts trailing commas
  2. This CatchClause convenience initializer adds trailing space to the catch keyword

Copy link
Member

Choose a reason for hiding this comment

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

  1. I really don’t like the idea of introducing yet another type for catch items. We now have CatchItemsListSyntax, CatchItemsList and CatchItems. What do you think about adding an initializer like the following to CatchItemList. We could add the same for all syntax collections:
public init(@CatchItemListBuilder itemsBuilder: () -> ExpressibleAsCatchItemList) {
  self = itemsBuilder().createCatchItemList()
}
  1. Can’t we just mark the catch keyword as requires_trailing_space in https://github.com/apple/swift/blob/5dfa894ea773c1cb82106d831cd4d2df4a837b75/utils/gyb_syntax_support/Token.py#L188?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Great idea, I've raised Element List initializers accepting result builder #519 for it
  2. I actually did the opposite to avoid double space when there is no catch items, so I'd like to keep this convenience initializer

@@ -22,7 +22,7 @@ final class StructTests: XCTestCase {
let nestedStruct = StructDecl(
structKeyword: .struct.withLeadingTrivia(.docLineComment("/// A nested struct\n")),
identifier: "NestedStruct",
genericParameterClause: GenericParameterClause {
genericParameterClause: GenericParameterClause(rightAngleBracket: .rightAngle.withoutTrailingTrivia()) {
Copy link
Member

Choose a reason for hiding this comment

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

I’m not sure how big the changes for the angle brackets are but feel free to include them in this PR.

@evnik evnik marked this pull request as draft July 26, 2022 20:05
@evnik evnik marked this pull request as ready for review July 30, 2022 20:22
@evnik
Copy link
Contributor Author

evnik commented Aug 4, 2022

@ahoppen any comments for the updated implementation?

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Sorry that I missed this. LGTM.

@ahoppen
Copy link
Member

ahoppen commented Aug 4, 2022

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Aug 4, 2022

swiftlang/swift#60204

@swift-ci Please test

1 similar comment
@ahoppen
Copy link
Member

ahoppen commented Aug 4, 2022

swiftlang/swift#60204

@swift-ci Please test

* Leading/trailing spaces are updated to make statements well formatted
* `CatchClause` convenience initializer that calculates spacing
  around the `catch` keyword
* Test coverage for above changes
@ahoppen
Copy link
Member

ahoppen commented Aug 5, 2022

swiftlang/swift#60204

@swift-ci Please test

@ahoppen ahoppen merged commit 7a97341 into swiftlang:main Aug 5, 2022
@evnik evnik deleted the Trivia branch August 5, 2022 15:39
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