mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: save newlines between array elements
This commit is contained in:
parent
4fe4709b56
commit
a18201faa7
@ -469,7 +469,15 @@ fn (var f Fmt) expr(node ast.Expr) {
|
||||
// `[1,2,3]`
|
||||
// type_sym := f.table.get_type_symbol(it.typ)
|
||||
f.write('[')
|
||||
var inc_indent := false
|
||||
var line_nr := node.position().line_nr // to have the same newlines between array elements
|
||||
for i, expr in it.exprs {
|
||||
pos := expr.position()
|
||||
if i == 0 && line_nr < pos.line_nr {
|
||||
f.writeln('')
|
||||
f.indent++
|
||||
inc_indent = true
|
||||
}
|
||||
if i > 0 && it.exprs.len > 1 {
|
||||
f.wrap_long_line()
|
||||
}
|
||||
@ -477,6 +485,13 @@ fn (var f Fmt) expr(node ast.Expr) {
|
||||
if i < it.exprs.len - 1 {
|
||||
f.write(', ')
|
||||
}
|
||||
if line_nr < pos.line_nr {
|
||||
f.writeln('')
|
||||
}
|
||||
line_nr = pos.line_nr
|
||||
}
|
||||
if inc_indent {
|
||||
f.indent--
|
||||
}
|
||||
f.write(']')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user