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) {
|
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))
|
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)
|
before_comments := field.comments.filter(it.pos.pos < field.pos.pos)
|
||||||
between_comments := field.comments[before_comments.len..].filter(it.pos.pos < end_pos)
|
end_comments := field.comments.filter(it.pos.pos > field.pos.pos)
|
||||||
after_type_comments := field.comments[(before_comments.len + between_comments.len)..]
|
if before_comments.len > 0 {
|
||||||
|
f.comments(before_comments, level: .indent)
|
||||||
|
}
|
||||||
f.write('\t${field.name} ${ft}')
|
f.write('\t${field.name} ${ft}')
|
||||||
if after_type_comments.len > 0 {
|
if end_comments.len > 0 {
|
||||||
f.comments(after_type_comments, level: .indent)
|
f.comments(end_comments, level: .indent)
|
||||||
} else {
|
} else {
|
||||||
f.writeln('')
|
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
|
info.methods << tmethod
|
||||||
} else {
|
} else {
|
||||||
// interface fields
|
// interface fields
|
||||||
|
mut comments := p.eat_comments()
|
||||||
field_pos := p.tok.pos()
|
field_pos := p.tok.pos()
|
||||||
field_name := p.check_name()
|
field_name := p.check_name()
|
||||||
mut type_pos := p.tok.pos()
|
mut type_pos := p.tok.pos()
|
||||||
field_typ := p.parse_type()
|
field_typ := p.parse_type()
|
||||||
type_pos = type_pos.extend(p.prev_tok.pos())
|
type_pos = type_pos.extend(p.prev_tok.pos())
|
||||||
mut comments := []ast.Comment{}
|
comments << p.eat_comments(same_line: true)
|
||||||
for p.tok.kind == .comment {
|
|
||||||
comments << p.comment()
|
|
||||||
if p.tok.kind == .rcbr {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fields << ast.StructField{
|
fields << ast.StructField{
|
||||||
name: field_name
|
name: field_name
|
||||||
pos: field_pos
|
pos: field_pos
|
||||||
|
Loading…
Reference in New Issue
Block a user