fmt: fix linebreak in non-block consts (#9260)
parent
2fbacd0e79
commit
cfbb783649
|
@ -1911,11 +1911,11 @@ pub fn (mut f Fmt) map_init(it ast.MapInit) {
|
||||||
f.write('}')
|
f.write('}')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
|
pub fn (mut f Fmt) const_decl(node ast.ConstDecl) {
|
||||||
if it.is_pub {
|
if node.is_pub {
|
||||||
f.write('pub ')
|
f.write('pub ')
|
||||||
}
|
}
|
||||||
if it.fields.len == 0 && it.pos.line_nr == it.pos.last_line {
|
if node.fields.len == 0 && node.pos.line_nr == node.pos.last_line {
|
||||||
f.writeln('const ()\n')
|
f.writeln('const ()\n')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1924,18 +1924,18 @@ pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
|
||||||
f.inside_const = false
|
f.inside_const = false
|
||||||
}
|
}
|
||||||
f.write('const ')
|
f.write('const ')
|
||||||
if it.is_block {
|
|
||||||
f.writeln('(')
|
|
||||||
}
|
|
||||||
mut max := 0
|
mut max := 0
|
||||||
for field in it.fields {
|
if node.is_block {
|
||||||
|
f.writeln('(')
|
||||||
|
for field in node.fields {
|
||||||
if field.name.len > max {
|
if field.name.len > max {
|
||||||
max = field.name.len
|
max = field.name.len
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.indent++
|
f.indent++
|
||||||
mut prev_field := if it.fields.len > 0 { ast.Node(it.fields[0]) } else { ast.Node{} }
|
}
|
||||||
for field in it.fields {
|
mut prev_field := if node.fields.len > 0 { ast.Node(node.fields[0]) } else { ast.Node{} }
|
||||||
|
for field in node.fields {
|
||||||
if field.comments.len > 0 {
|
if field.comments.len > 0 {
|
||||||
if f.should_insert_newline_before_node(ast.Expr(field.comments[0]), prev_field) {
|
if f.should_insert_newline_before_node(ast.Expr(field.comments[0]), prev_field) {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
|
@ -1943,7 +1943,7 @@ pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
|
||||||
f.comments(field.comments, inline: true)
|
f.comments(field.comments, inline: true)
|
||||||
prev_field = ast.Expr(field.comments.last())
|
prev_field = ast.Expr(field.comments.last())
|
||||||
}
|
}
|
||||||
if f.should_insert_newline_before_node(field, prev_field) {
|
if node.is_block && f.should_insert_newline_before_node(field, prev_field) {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
name := field.name.after('.')
|
name := field.name.after('.')
|
||||||
|
@ -1954,9 +1954,9 @@ pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
prev_field = field
|
prev_field = field
|
||||||
}
|
}
|
||||||
f.comments_after_last_field(it.end_comments)
|
f.comments_after_last_field(node.end_comments)
|
||||||
|
if node.is_block {
|
||||||
f.indent--
|
f.indent--
|
||||||
if it.is_block {
|
|
||||||
f.writeln(')\n')
|
f.writeln(')\n')
|
||||||
} else {
|
} else {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
const font = $embed_file('../assets/fonts/RobotoMono-Regular.ttf')
|
Loading…
Reference in New Issue