fmt: keep lines of comments inside an array (#8420)
parent
2a32dac40d
commit
93acc929f7
|
@ -1929,8 +1929,16 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
|
||||||
}
|
}
|
||||||
f.expr(expr)
|
f.expr(expr)
|
||||||
if i < it.ecmnts.len && it.ecmnts[i].len > 0 {
|
if i < it.ecmnts.len && it.ecmnts[i].len > 0 {
|
||||||
f.write(' ')
|
mut last_cmt := it.ecmnts[i][0]
|
||||||
|
if last_cmt.pos.line_nr > expr.position().last_line {
|
||||||
|
f.writeln('')
|
||||||
|
} else {
|
||||||
|
f.write(' ')
|
||||||
|
}
|
||||||
for cmt in it.ecmnts[i] {
|
for cmt in it.ecmnts[i] {
|
||||||
|
if cmt.pos.line_nr > last_cmt.pos.last_line {
|
||||||
|
f.writeln('')
|
||||||
|
}
|
||||||
f.comment(cmt, iembed: true)
|
f.comment(cmt, iembed: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
fn only_comments_array() {
|
||||||
|
arr := [
|
||||||
|
/* 1, */
|
||||||
|
/* 2, */
|
||||||
|
/* 3, */
|
||||||
|
/* 4, */
|
||||||
|
]
|
||||||
|
arr2 := [
|
||||||
|
/* 1, */ /* 2, *//* 3, */
|
||||||
|
/* 4, */
|
||||||
|
]
|
||||||
|
}
|
|
@ -40,7 +40,8 @@ fn main() {
|
||||||
e := c
|
e := c
|
||||||
// more comments = more good
|
// more comments = more good
|
||||||
arr := [
|
arr := [
|
||||||
/* block foo bar */ /* inline foo bar */
|
/* block foo bar */
|
||||||
|
/* inline foo bar */
|
||||||
0,
|
0,
|
||||||
]
|
]
|
||||||
// before arg comment
|
// before arg comment
|
||||||
|
|
Loading…
Reference in New Issue