fmt: keep interface comments between methods (#7650)
parent
97bfabf194
commit
4783503185
|
@ -312,6 +312,7 @@ pub mut:
|
|||
stmts []Stmt
|
||||
return_type table.Type
|
||||
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
||||
next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl
|
||||
source_file &File = 0
|
||||
scope &Scope
|
||||
}
|
||||
|
|
|
@ -715,6 +715,7 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
|||
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
|
||||
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
|
||||
f.writeln('')
|
||||
f.comments(method.next_comments, inline: false, has_nl: true, level: .indent)
|
||||
}
|
||||
f.writeln('}\n')
|
||||
}
|
||||
|
|
|
@ -2,3 +2,30 @@ pub interface ReaderWriter {
|
|||
read(mut buf []byte) ?int // from Reader
|
||||
write(buf []byte) ?int // from Writer
|
||||
}
|
||||
|
||||
interface Speaker {
|
||||
// first
|
||||
speak() string
|
||||
// between
|
||||
foo() string
|
||||
foo2() string
|
||||
// last
|
||||
}
|
||||
|
||||
interface Baz {
|
||||
// first
|
||||
speak() string
|
||||
// comment
|
||||
// more between
|
||||
foo() string
|
||||
foo2() string
|
||||
// last
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
speak() string // after
|
||||
foo() string
|
||||
speak2() string // also after
|
||||
// and between
|
||||
foo2() string
|
||||
}
|
||||
|
|
|
@ -455,8 +455,10 @@ 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()
|
||||
}
|
||||
mcomments := p.eat_comments()
|
||||
mcomments := p.eat_line_end_comments()
|
||||
mnext_comments := p.eat_comments()
|
||||
method.comments = mcomments
|
||||
method.next_comments = mnext_comments
|
||||
methods << method
|
||||
// println('register method $name')
|
||||
ts.register_method(name: name, params: args, return_type: method.return_type, is_pub: true)
|
||||
|
|
Loading…
Reference in New Issue