fmt: keep comment between enum fields (#7566)

pull/7567/head
Lukas Neubert 2020-12-25 20:41:59 +01:00 committed by GitHub
parent 270ba07e83
commit 2c0fba5480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View File

@ -760,11 +760,12 @@ pub mut:
pub struct EnumField { pub struct EnumField {
pub: pub:
name string name string
pos token.Position pos token.Position
comments []Comment comments []Comment
expr Expr next_comments []Comment
has_expr bool expr Expr
has_expr bool
} }
pub struct EnumDecl { pub struct EnumDecl {

View File

@ -739,6 +739,7 @@ pub fn (mut f Fmt) enum_decl(node ast.EnumDecl) {
} }
f.comments(field.comments, inline: true, has_nl: false, level: .indent) f.comments(field.comments, inline: true, has_nl: false, level: .indent)
f.writeln('') f.writeln('')
f.comments(field.next_comments, inline: false, has_nl: true, level: .indent)
} }
f.writeln('}\n') f.writeln('}\n')
} }

View File

@ -1,3 +1,11 @@
enum Abc {
a
b // after a value
c
// between values
d
}
struct User { struct User {
name string // name name string // name
// middle comment // middle comment

View File

@ -1965,7 +1965,8 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
pos: pos pos: pos
expr: expr expr: expr
has_expr: has_expr has_expr: has_expr
comments: p.eat_comments() comments: p.eat_line_end_comments()
next_comments: p.eat_comments()
} }
} }
p.top_level_statement_end() p.top_level_statement_end()