Skip to content

Insert a space before colon in ternary expression in Fix-It #1641

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 3 commits into from
May 13, 2023

Conversation

gibachan
Copy link
Contributor

@gibachan gibachan commented May 8, 2023

This pull request addresses #1607

@gibachan gibachan requested a review from ahoppen as a code owner May 8, 2023 05:16
@kimdv kimdv linked an issue May 8, 2023 that may be closed by this pull request
@kimdv
Copy link
Contributor

kimdv commented May 8, 2023

@swift-ci please test

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.

@gibachan, welcome to SwiftSyntax’s development.

I would prefer to adjust the formatting in BasicFormat instead of ParseDiagnsoticsGenerator because that way we also get the correct formatting you you are constructing a ternary operator e.g. from SwiftSyntaxBuilder, which is what people will do when writing macros.

In that case, it should work both when the operators are folded and when they haven’t been folded yet (see https://swiftpackageindex.com/apple/swift-syntax/main/documentation/swiftoperators).

An unfolded ternary operator would be the following

SequenceExprSyntax {
  BooleanLiteralExprSyntax(true)
  UnresolvedTernaryExprSyntax(firstChoice: IntegerLiteralExprSyntax(1))
  IntegerLiteralExprSyntax(0)
}

and a folded ternary operator would be

TernaryExprSyntax(
  conditionExpression: BooleanLiteralExprSyntax(true),
  firstChoice: IntegerLiteralExprSyntax(1),
  secondChoice: IntegerLiteralExprSyntax(0)
)

The code that you’d like to change is most likely in here https://github.com/apple/swift-syntax/blob/cecb0340a95f00f8f2725c912b494266ed7b4a80/Sources/SwiftBasicFormat/BasicFormat.swift#L177

@gibachan
Copy link
Contributor Author

gibachan commented May 9, 2023

Thank you for your feedback. I'll take a look into it!

@gibachan gibachan requested a review from ahoppen May 10, 2023 09:00
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.

Thanks. This looks great! I’ve got one slight comment on how to improve implementation, otherwise this is ready to be merged. 👍🏽

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.

Thank you for your contribution, @gibachan. This looks good to me. Once CI passes, I’ll merge the PR.

@ahoppen
Copy link
Member

ahoppen commented May 12, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge May 12, 2023 20:31
@ahoppen
Copy link
Member

ahoppen commented May 12, 2023

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member

ahoppen commented May 13, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 9f61d4a into swiftlang:main May 13, 2023
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.

Wrong spacing around : in Fix-It for ternary expressions
3 participants