Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,14 @@ pub fn (mut f Fmt) interface_field(field ast.StructField) {
}

pub fn (mut f Fmt) interface_method(method ast.FnDecl) {
before_comments := method.comments.filter(it.pos.pos < method.pos.pos)
end_comments := method.comments.filter(it.pos.pos > method.pos.pos)
if before_comments.len > 0 {
f.comments(before_comments, level: .indent)
}
f.write('\t')
f.write(method.stringify_fn_decl(f.table, f.cur_mod, f.mod2alias).all_after_first('fn '))
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
f.comments(end_comments, inline: true, has_nl: false, level: .indent)
f.writeln('')
f.comments(method.next_comments, inline: false, has_nl: true, level: .indent)
for param in method.params {
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/fmt/tests/interface_method_with_pre_comments_keep.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module main

fn main() {
}

pub interface IOperateResult {
mut:
// is_success
is_success bool
// is_show_msg
is_show_msg bool
// msg
msg string
// comment before method def
set_msg(msg string) // comment after method def
}
6 changes: 3 additions & 3 deletions vlib/v/parser/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
p.peek_tok.pos())
return ast.InterfaceDecl{}
}
mut comments := p.eat_comments()
if p.peek_tok.kind == .lpar {
method_start_pos := p.tok.pos()
line_nr := p.tok.line_nr
Expand Down Expand Up @@ -687,9 +688,9 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
method.return_type_pos = method.return_type_pos.extend(p.tok.pos())
method.pos = method.pos.extend(method.return_type_pos)
}
mcomments := p.eat_comments(same_line: true)
comments << p.eat_comments(same_line: true)
mnext_comments := p.eat_comments()
method.comments = mcomments
method.comments = comments
method.next_comments = mnext_comments
methods << method
tmethod := ast.Fn{
Expand All @@ -706,7 +707,6 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
info.methods << tmethod
} else {
// interface fields
mut comments := p.eat_comments()
field_pos := p.tok.pos()
field_name := p.check_name()
mut type_pos := p.tok.pos()
Expand Down