Skip to content

Automatically format expanded macros #1591

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
Apr 28, 2023

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Apr 26, 2023

Rather than requiring macro implementations to add required whitespace and indentation, basic format all macro expansions. Right now this uses the default four space indentation, we can consider having that inferred later. Macros can opt-out of automatic formatting by implementing formatMode and setting it to .disabled.

Add new trimmed(matching:) and trimmedDescription(matching:) methods
to allow eg. only trimming whitespace rather than all trivia. Use this
when trimming macro expansions so that any added comments are kept.

Resolves rdar://107731047.

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham bnbarham force-pushed the format-macro-expansions branch 2 times, most recently from 4d2d3d5 to efcc899 Compare April 27, 2023 15:46
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham bnbarham force-pushed the format-macro-expansions branch from efcc899 to c5bb157 Compare April 27, 2023 23:15
@bnbarham
Copy link
Contributor Author

@swift-ci please test

Rather than requiring macro implementations to add required whitespace
and indentation, basic format all macro expansions. Right now this uses
the default four space indentation, we can consider having that inferred
later. Macros can opt-out of automatic formatting by implementing
`formatMode` and setting it to `.disabled`.

Add new `trimmed(matching:)` and `trimmedDescription(matching:)` methods
to allow eg. only trimming whitespace rather than all trivia. Use this
when trimming macro expansions so that any added comments are kept.

Resolves rdar://107731047.
@bnbarham bnbarham force-pushed the format-macro-expansions branch from c5bb157 to e40c82c Compare April 28, 2023 04:23
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test Windows platform

@bnbarham
Copy link
Contributor Author

@swift-ci please test Windows platform

@bnbarham bnbarham merged commit e88e4e2 into swiftlang:main Apr 28, 2023
@bnbarham bnbarham deleted the format-macro-expansions branch April 28, 2023 23:20
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.

3 participants