mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
e0aba77cc5
commit
b25288338c
@ -1290,13 +1290,14 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||
|
||||
pub fn (mut f Fmt) interface_field(field ast.StructField) {
|
||||
ft := f.no_cur_mod(f.table.type_to_str_using_aliases(field.typ, f.mod2alias))
|
||||
end_pos := field.pos.pos + field.pos.len
|
||||
before_comments := field.comments.filter(it.pos.pos < field.pos.pos)
|
||||
between_comments := field.comments[before_comments.len..].filter(it.pos.pos < end_pos)
|
||||
after_type_comments := field.comments[(before_comments.len + between_comments.len)..]
|
||||
end_comments := field.comments.filter(it.pos.pos > field.pos.pos)
|
||||
if before_comments.len > 0 {
|
||||
f.comments(before_comments, level: .indent)
|
||||
}
|
||||
f.write('\t${field.name} ${ft}')
|
||||
if after_type_comments.len > 0 {
|
||||
f.comments(after_type_comments, level: .indent)
|
||||
if end_comments.len > 0 {
|
||||
f.comments(end_comments, level: .indent)
|
||||
} else {
|
||||
f.writeln('')
|
||||
}
|
||||
|
14
vlib/v/fmt/tests/interface_fields_with_pre_comments_keep.vv
Normal file
14
vlib/v/fmt/tests/interface_fields_with_pre_comments_keep.vv
Normal file
@ -0,0 +1,14 @@
|
||||
module main
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
pub interface IOperateInfo {
|
||||
mut:
|
||||
// title
|
||||
title string
|
||||
// msg
|
||||
msg string
|
||||
// id
|
||||
id string
|
||||
}
|
@ -702,18 +702,13 @@ 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()
|
||||
field_typ := p.parse_type()
|
||||
type_pos = type_pos.extend(p.prev_tok.pos())
|
||||
mut comments := []ast.Comment{}
|
||||
for p.tok.kind == .comment {
|
||||
comments << p.comment()
|
||||
if p.tok.kind == .rcbr {
|
||||
break
|
||||
}
|
||||
}
|
||||
comments << p.eat_comments(same_line: true)
|
||||
fields << ast.StructField{
|
||||
name: field_name
|
||||
pos: field_pos
|
||||
|
Loading…
Reference in New Issue
Block a user