fmt: keep interface comments between methods (#7650)

pull/7658/head
Lukas Neubert 2020-12-28 17:14:55 +01:00 committed by GitHub
parent 97bfabf194
commit 4783503185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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