-
Notifications
You must be signed in to change notification settings - Fork 926
Format comments with different opening in different manner #1604
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
This PR adds tests for rust-lang#325, rust-lang#1092, rust-lang#1214, rust-lang#1278, rust-lang#1329 and rust-lang#1427.
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.
Thanks for the PR, I think the overall design is good and factoring out the CommentStyle enum is a good call. I have a couple of places where this might be improved in small ways.
src/comment.rs
Outdated
(self.opener(orig), self.closer(), self.line_start(orig)) | ||
} | ||
|
||
pub fn to_pattern<'a>(&self, line: &str, orig: &'a str, normalize_comments: bool) -> bool { |
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.
I'm not sure what this function is doing, I think the name is not ideal because I would expect to_pattern
to convert a CommentStyle into a Pattern.
src/comment.rs
Outdated
if rest.is_empty() { | ||
Some(first_group_str) | ||
} else { | ||
rewrite_comment(&rest, block_style, shape, config).map(|rest_str| { |
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 have rewrite_comment
and rewrite_comment_inner
where the latter recurses, could we have a rewrite_comment
function which calls an identify_comment
where identify_comment
is recursive?
52b7002
to
bcebe9e
Compare
Thank you! Rebased reflecting the feedbacks.
|
-> Option<String> { | ||
let style = comment_style(orig, false); | ||
let first_group = orig.lines() | ||
.take_while(|l| style.line_with_same_comment_style(l, orig, false)) |
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.
I was wondering if rust has a function equivalent to span
in haskell.
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.
I don't think there is one - there might be one in Itertools, but I prefer not to link it and use simpler functions.
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.
You might be able to use partition
Thanks for the changes! |
This PR closes #691.
However, TBH I am not sure whether how I deal with this issue is ideal.
Introducing
enum CommentStyle
seems overkill after looking back this PR.I really appreciate any feedbacks.
Thank you in advance!