1
0
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:
Delyan Angelov 2020-11-05 18:23:45 +02:00
parent 4051ce869c
commit 35096cda3f
4 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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')
}

View File

@ -0,0 +1,4 @@
pub interface ReaderWriter {
read(mut buf []byte) ?int // from Reader
write(buf []byte) ?int // from Writer
}

View File

@ -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)