fmt: keep lines of comments inside an array (#8420)

pull/7529/head
Lukas Neubert 2021-01-29 19:19:14 +01:00 committed by GitHub
parent 2a32dac40d
commit 93acc929f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -1929,8 +1929,16 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
}
f.expr(expr)
if i < it.ecmnts.len && it.ecmnts[i].len > 0 {
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] {
if cmt.pos.line_nr > last_cmt.pos.last_line {
f.writeln('')
}
f.comment(cmt, iembed: true)
}
}

View File

@ -0,0 +1,12 @@
fn only_comments_array() {
arr := [
/* 1, */
/* 2, */
/* 3, */
/* 4, */
]
arr2 := [
/* 1, */ /* 2, *//* 3, */
/* 4, */
]
}

View File

@ -40,7 +40,8 @@ fn main() {
e := c
// more comments = more good
arr := [
/* block foo bar */ /* inline foo bar */
/* block foo bar */
/* inline foo bar */
0,
]
// before arg comment