Add support for PatternMatchMapping formatting#6836
Merged
charliermarsh merged 1 commit intomainfrom Aug 25, 2023
Merged
Conversation
fe109a9 to
507f5bc
Compare
Member
Author
|
We may want to instead change the |
Contributor
PR Check ResultsBenchmarkLinuxWindows |
MichaReiser
approved these changes
Aug 24, 2023
Member
MichaReiser
left a comment
There was a problem hiding this comment.
I love it how you came in and are pushing match formatting over the line!
| let dangling = comments.dangling(item); | ||
|
|
||
| if keys.is_empty() && rest.is_none() { | ||
| return empty_parenthesized("{", dangling, "}").fmt(f); |
Member
There was a problem hiding this comment.
Lol, Our DSL sometimes is too powerful. I was like, whoot, since when does &[SourceComment] implement Format but it's empty_parenthesized that accepts comments.
crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs
Outdated
Show resolved
Hide resolved
crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs
Outdated
Show resolved
Hide resolved
crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs
Outdated
Show resolved
Hide resolved
crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs
Outdated
Show resolved
Hide resolved
konstin
approved these changes
Aug 24, 2023
43d68ac to
23ec21d
Compare
23ec21d to
4bd3380
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for
PatternMatchMapping-- i.e., cases like:Unfortunately, this node has three kinds of dangling comments:
{ # "open parenthesis comment" key: pattern, ** # end-of-line "double star comment" # own-line "double star comment" rest # end-of-line "after rest comment" # own-line "after rest comment" }Some of the complexity comes from the fact that in
**rest,restis an identifier, not a node, so we have to handle comments after it as dangling on the enclosing node, rather than trailing on**rest. (We could change the AST to usePatternMatchAsthere, which would be more permissive than the grammar but not totally crazy --PatternMatchAsis used elsewhere to mean "a single identifier".)Closes #6644.
Test Plan
cargo test