Repository navigation
Format comments with different opening in different manner - #1604
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.
nrc
left a comment
There was a problem hiding this comment.
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.
| (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.
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.
| 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.
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.
I was wondering if rust has a function equivalent to span in haskell.
There was a problem hiding this comment.
I don't think there is one - there might be one in Itertools, but I prefer not to link it and use simpler functions.
|
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 CommentStyleseems overkill after looking back this PR.I really appreciate any feedbacks.
Thank you in advance!