fmt: fix missing space after single line array pre comments (#8904)

pull/8906/head
Lukas Neubert 2021-02-22 16:53:55 +01:00 committed by GitHub
parent fb028abc71
commit 7f6c4caa01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -255,7 +255,7 @@ pub fn (x Expr) str() string {
return '/* $lines.len lines comment */'
} else {
text := x.text.trim('\x01').trim_space()
return '// $text'
return '´// $text´'
}
}
ComptimeSelector {

View File

@ -1970,9 +1970,14 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
f.comment(c, level: .indent, iembed: true)
last_line_nr = c.pos.last_line
}
if it.exprs.len == 0 && it.pre_cmnts.len > 0 && it.pre_cmnts[0].pos.line_nr != it.pos.line_nr {
if it.pre_cmnts.len > 0 {
same_line := it.pre_cmnts[0].pos.line_nr == it.pos.line_nr
if same_line && it.exprs.len > 0 {
f.write(' ')
} else if !same_line && it.exprs.len == 0 {
f.writeln('')
}
}
for i, expr in it.exprs {
line_nr := expr.position().line_nr
if i == 0 {

View File

@ -10,3 +10,8 @@ fn only_comments_array() {
/* 4, */
]
}
fn array_pre_comments() {
_ := [/* 2, */ 3]
_ := [/* 4, */ /* 5, */ 6]
}