mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: handle comments after last const field
This commit is contained in:
parent
f5c245ceb8
commit
7476428def
@ -162,6 +162,7 @@ pub:
|
|||||||
pos token.Position
|
pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
fields []ConstField
|
fields []ConstField
|
||||||
|
end_comments []Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StructDecl {
|
pub struct StructDecl {
|
||||||
|
@ -677,8 +677,13 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||||||
}
|
}
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
}
|
}
|
||||||
|
f.comments_after_last_field(node.end_comments)
|
||||||
|
f.writeln('}\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut f Fmt) comments_after_last_field(comments []ast.Comment) {
|
||||||
// Handle comments after last field
|
// Handle comments after last field
|
||||||
for comment in node.end_comments {
|
for comment in comments {
|
||||||
f.indent++
|
f.indent++
|
||||||
f.empty_line = true
|
f.empty_line = true
|
||||||
f.comment(comment, {
|
f.comment(comment, {
|
||||||
@ -687,7 +692,6 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||||||
f.writeln('')
|
f.writeln('')
|
||||||
f.indent--
|
f.indent--
|
||||||
}
|
}
|
||||||
f.writeln('}\n')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||||
@ -1814,6 +1818,7 @@ pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
|
|||||||
f.expr(field.expr)
|
f.expr(field.expr)
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
|
f.comments_after_last_field(it.end_comments)
|
||||||
f.indent--
|
f.indent--
|
||||||
f.writeln(')\n')
|
f.writeln(')\n')
|
||||||
}
|
}
|
||||||
|
4
vlib/v/fmt/tests/consts_with_comments_keep.vv
Normal file
4
vlib/v/fmt/tests/consts_with_comments_keep.vv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
const (
|
||||||
|
fsm_state_array = ['init', 'state_a', 'state_b', 'state_c', 'exit'] // use as a first half key for map see fsm_state_ev_fn, the same order as in enum FSM_state
|
||||||
|
fsm_event_array = ['ev1', 'ev2', 'ev3', 'ev4', 'ev5'] // use as a second half key for map see fsm_state_ev_fn, the same order as in enum FSM_event
|
||||||
|
)
|
@ -1602,13 +1602,11 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||||||
}
|
}
|
||||||
p.next() // (
|
p.next() // (
|
||||||
mut fields := []ast.ConstField{}
|
mut fields := []ast.ConstField{}
|
||||||
for p.tok.kind != .rpar {
|
mut comments := []ast.Comment{}
|
||||||
mut comments := []ast.Comment{}
|
for {
|
||||||
for p.tok.kind == .comment {
|
comments = p.eat_comments()
|
||||||
comments << p.comment()
|
if p.tok.kind == .rpar {
|
||||||
if p.tok.kind == .rpar {
|
break
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pos := p.tok.position()
|
pos := p.tok.position()
|
||||||
name := p.check_name()
|
name := p.check_name()
|
||||||
@ -1630,6 +1628,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||||||
}
|
}
|
||||||
fields << field
|
fields << field
|
||||||
p.global_scope.register(field.name, field)
|
p.global_scope.register(field.name, field)
|
||||||
|
comments = []
|
||||||
}
|
}
|
||||||
p.top_level_statement_end()
|
p.top_level_statement_end()
|
||||||
p.check(.rpar)
|
p.check(.rpar)
|
||||||
@ -1637,6 +1636,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||||||
pos: start_pos.extend(end_pos)
|
pos: start_pos.extend(end_pos)
|
||||||
fields: fields
|
fields: fields
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
|
end_comments: comments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user