1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: keep one empty line in struct decl (#8782)

This commit is contained in:
zakuro 2021-02-17 13:45:09 +09:00 committed by GitHub
parent 55b69a76a6
commit 3341c17202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -696,6 +696,24 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
f.writeln('__global:')
} else if i == node.module_pos {
f.writeln('module:')
} else if i > 0 {
// keep one empty line between fields (exclude one after mut:, pub:, ...)
mut before_last_line := node.fields[i - 1].pos.line_nr
if node.fields[i - 1].comments.len > 0 {
before_last_line = util.imax(before_last_line, node.fields[i - 1].comments.last().pos.last_line)
}
if node.fields[i - 1].has_default_expr {
before_last_line = util.imax(before_last_line, node.fields[i - 1].default_expr.position().last_line)
}
mut next_first_line := field.pos.line_nr
if field.comments.len > 0 {
next_first_line = util.imin(next_first_line, field.comments[0].pos.line_nr)
}
println('$field.name $next_first_line $before_last_line')
if next_first_line - before_last_line > 1 {
f.writeln('')
}
}
end_pos := field.pos.pos + field.pos.len
before_comments := field.comments.filter(it.pos.pos < field.pos.pos)

View File

@ -51,6 +51,8 @@ mut:
somefield2 /* 11 */ int // 12
pub:
somefield3 int
somefield4 int
/*
13
14

View File

@ -47,7 +47,15 @@ somefield /*4*/ /*5*/ int /*6*/ /*7*/ /*8*/ /*
*/
somefield2 /*11*/ int // 12
pub:
somefield3 int
somefield4 int
/*
13
14