-
Notifications
You must be signed in to change notification settings - Fork 926
Add implementation of match arm alignment #1704
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
Conversation
Thanks for implementing this, it looks pretty good! I have a few high level comments: I'd prefer to avoid a I'm a bit surprised by how much whitespace is introduced. I would expect that the longest pattern always gets exactly one space before the expression, e.g.,
Is there a reason not to? |
Yes, I agree that it should always reformat to the minimum amount of spacing. I'll make that change. As for match lorem {
Lorem::Ipsum => {
lorem();
ipsum();
},
Lorem::DolorSitAmetConsecteturAdipiscingElitSedDo => (),
Lorem::Eiusmod => {
lorem();
ipsum();
},
} It would add a lot of unnecessary whitespace to the other statements. |
I replaced match lorem {
Lorem::Ipsum => (),
Lorem::Dolor => (),
Lorem::Sit => (),
Lorem::Amet => (),
}
match lorem {
Lorem::Ipsum => {
lorem();
ipsum();
},
Lorem::DolorSitAmetConsecteturAdipiscingElitSedDo => (),
Lorem::Eiusmod => {
lorem();
ipsum();
},
} becomes: match lorem {
Lorem::Ipsum => (),
Lorem::Dolor => (),
Lorem::Sit => (),
Lorem::Amet => (),
}
match lorem {
Lorem::Ipsum => {
lorem();
ipsum();
},
Lorem::DolorSitAmetConsecteturAdipiscingElitSedDo => (),
Lorem::Eiusmod => {
lorem();
ipsum();
},
} |
Could we have just a single config option like |
Sure, sounds good to me. |
@@ -222,6 +222,8 @@ pub struct Shape { | |||
// Indentation + any already emitted text on the first line of the current | |||
// statement. | |||
pub offset: usize, | |||
// Alignment to other structures | |||
pub alignment: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than add this to Shape
, can you pass this as an extra arg to the relevant functions?
@topecongiro would you be able to give this a review please? @Ruin0x11 also needs rebasing before we can merge |
I added the tests, and as expected they don't. However I'm wondering what the best way of getting the relative position is using only each arm. |
@Ruin0x11 Do you have any updates? let x = match op {
Some(Foo( .. )) => 0,
None => 1,
}; I think we have to first rewrite all the patterns and calculate the alignment using those results. |
Yes, that was the same conclusion I came to. This turned out to be way harder than I imagined. |
@Ruin0x11 In case you are not interested in to this anymore, please let me know. |
I think I'll open another PR when I can resolve the above issues. |
This is a draft of the "match_align_arms" functionality described in #894. Regression tests are included.