-
Notifications
You must be signed in to change notification settings - Fork 927
Proper indentation of multiline post-comments in a list #4572
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,6 +461,13 @@ where | |
|
||
let mut formatted_comment = rewrite_post_comment(&mut item_max_width)?; | ||
|
||
// Mmultiline comments are not included in a previous "indentation group". | ||
// Each multiline comment is a considered as a separage group. | ||
if formatted_comment.contains('\n') { | ||
item_max_width = None; | ||
formatted_comment = rewrite_post_comment(&mut item_max_width)?; | ||
} | ||
|
||
if !starts_with_newline(comment) { | ||
if formatting.align_comments { | ||
let mut comment_alignment = post_comment_alignment( | ||
|
@@ -537,10 +544,21 @@ where | |
for item in items.clone().into_iter().skip(i) { | ||
let item = item.as_ref(); | ||
let inner_item_width = UnicodeSegmentation::graphemes(item.inner_as_ref(), true).count(); | ||
let post_comment_is_multiline = item | ||
.post_comment | ||
.as_ref() | ||
.map_or(false, |s| s.trim().contains('\n')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kind of a bummer to have to do the multi vs. single line check multiple times, but at first glance I don't see a good way of avoiding that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried to find solution, but one of the checks whether the comment is mutliline is done in a loop for identifying the group, and the other is done later when formatting each items. Adding |
||
|
||
// Each multiline comment is an "indentation group" on its own | ||
if first && post_comment_is_multiline { | ||
return inner_item_width; | ||
} | ||
|
||
if !first | ||
&& (item.is_different_group() | ||
|| item.post_comment.is_none() | ||
|| inner_item_width + overhead > max_budget) | ||
|| inner_item_width + overhead > max_budget | ||
|| post_comment_is_multiline) | ||
{ | ||
return max_width; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
fn main() { | ||
let v = [ | ||
"A", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"EEEEE", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
]; | ||
} | ||
|
||
fn main() { | ||
let v = [ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
"AAAAA", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"E", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
fn main() { | ||
let v = [ | ||
"A", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"EEEEE", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
]; | ||
} | ||
|
||
fn main() { | ||
let v = [ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
"AAAAA", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"E", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
]; | ||
} |
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.
Minor typos
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.
Done (with removing the first "a" in the second line)