vfmt: support comments after interface methods

pull/6757/head
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: pub mut:
stmts []Stmt stmts []Stmt
return_type table.Type return_type table.Type
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
} }
// break, continue // 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) f.comments_after_last_field(node.pre_comments)
for method in node.methods { for method in node.methods {
f.write('\t') 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') 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 { if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr {
method.return_type = p.parse_type() method.return_type = p.parse_type()
} }
method.comments = p.eat_comments()
methods << method methods << method
// println('register method $name') // println('register method $name')
return_type_sym := p.table.get_type_symbol(method.return_type) return_type_sym := p.table.get_type_symbol(method.return_type)