vfmt: fix enum field comments

pull/5627/head
Delyan Angelov 2020-07-02 17:39:56 +03:00
parent 132170f54c
commit d809bbb715
1 changed files with 9 additions and 4 deletions

View File

@ -315,14 +315,14 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
} }
name := it.name.after('.') name := it.name.after('.')
f.writeln('enum $name {') f.writeln('enum $name {')
f.comments(it.comments) f.comments(it.comments, false)
for field in it.fields { for field in it.fields {
f.write('\t$field.name') f.write('\t$field.name')
if field.has_expr { if field.has_expr {
f.write(' = ') f.write(' = ')
f.expr(field.expr) f.expr(field.expr)
} }
f.comments(it.comments) f.comments(field.comments, true)
f.writeln('') f.writeln('')
} }
f.writeln('}\n') f.writeln('}\n')
@ -1100,12 +1100,17 @@ pub fn (mut f Fmt) comment(node ast.Comment) {
f.writeln('*/') f.writeln('*/')
} }
pub fn (mut f Fmt) comments(some_comments []ast.Comment) { pub fn (mut f Fmt) comments(some_comments []ast.Comment, remove_last_new_line bool) {
for c in some_comments { for c in some_comments {
if !f.out.last_n(1)[0].is_space() { if !f.out.last_n(1)[0].is_space() {
f.write('\t') f.write('\t')
} }
f.indent++
f.comment(c) f.comment(c)
f.indent--
}
if remove_last_new_line {
f.remove_new_line()
} }
} }
@ -1328,7 +1333,7 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) {
f.writeln('}') f.writeln('}')
} }
} }
f.comments(branch.post_comments) f.comments(branch.post_comments, false)
} }
f.indent-- f.indent--
f.write('}') f.write('}')