mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: support comments after interface methods
This commit is contained in:
parent
4051ce869c
commit
35096cda3f
@ -273,6 +273,7 @@ pub:
|
||||
pub mut:
|
||||
stmts []Stmt
|
||||
return_type table.Type
|
||||
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
||||
}
|
||||
|
||||
// break, continue
|
||||
|
@ -688,7 +688,13 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||
f.comments_after_last_field(node.pre_comments)
|
||||
for method in node.methods {
|
||||
f.write('\t')
|
||||
f.writeln(method.stringify(f.table, f.cur_mod).after('fn '))
|
||||
f.write(method.stringify(f.table, f.cur_mod).after('fn '))
|
||||
f.comments(method.comments, {
|
||||
inline: true
|
||||
has_nl: false
|
||||
level: .indent
|
||||
})
|
||||
f.writeln('')
|
||||
}
|
||||
f.writeln('}\n')
|
||||
}
|
||||
|
4
vlib/v/fmt/tests/interface_declaration_comments_keep.vv
Normal file
4
vlib/v/fmt/tests/interface_declaration_comments_keep.vv
Normal file
@ -0,0 +1,4 @@
|
||||
pub interface ReaderWriter {
|
||||
read(mut buf []byte) ?int // from Reader
|
||||
write(buf []byte) ?int // from Writer
|
||||
}
|
@ -423,6 +423,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||
if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr {
|
||||
method.return_type = p.parse_type()
|
||||
}
|
||||
method.comments = p.eat_comments()
|
||||
methods << method
|
||||
// println('register method $name')
|
||||
return_type_sym := p.table.get_type_symbol(method.return_type)
|
||||
|
Loading…
Reference in New Issue
Block a user