v.fmt: keep comments after struct embeds

pull/10508/head
Delyan Angelov 2021-06-18 18:42:05 +03:00
parent de384f1cc8
commit d56ae2d508
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
6 changed files with 142 additions and 151 deletions

View File

@ -33,7 +33,6 @@ const (
'vlib/builtin/int.v' /* TODO byteptr: vfmt converts `pub fn (nn byteptr) str() string {` to `nn &byte` and that conflicts with `nn byte` */, 'vlib/builtin/int.v' /* TODO byteptr: vfmt converts `pub fn (nn byteptr) str() string {` to `nn &byte` and that conflicts with `nn byte` */,
'vlib/builtin/string_charptr_byteptr_helpers.v' /* TODO byteptr: a temporary shim to ease the byteptr=>&byte transition */, 'vlib/builtin/string_charptr_byteptr_helpers.v' /* TODO byteptr: a temporary shim to ease the byteptr=>&byte transition */,
'vlib/v/tests/interop_test.v', /* bad comment formatting */ 'vlib/v/tests/interop_test.v', /* bad comment formatting */
'vlib/v/tests/string_interpolation_test.v' /* TODO byteptr: &byte.str() behaves differently than byteptr.str() */,
'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */ 'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */
] ]
vfmt_verify_list = [ vfmt_verify_list = [
@ -43,7 +42,6 @@ const (
'vlib/', 'vlib/',
] ]
vfmt_known_failing_exceptions = arrays.merge(verify_known_failing_exceptions, [ vfmt_known_failing_exceptions = arrays.merge(verify_known_failing_exceptions, [
'vlib/term/ui/input.v' /* comment after a struct embed is removed */,
'vlib/regex/regex_test.v' /* contains meaningfull formatting of the test case data */, 'vlib/regex/regex_test.v' /* contains meaningfull formatting of the test case data */,
'vlib/readline/readline_test.v' /* vfmt eats `{ Readline }` from `import readline { Readline }` */, 'vlib/readline/readline_test.v' /* vfmt eats `{ Readline }` from `import readline { Readline }` */,
'vlib/glm/glm.v' /* `mut res &f32` => `mut res f32`, which then fails to compile */, 'vlib/glm/glm.v' /* `mut res &f32` => `mut res f32`, which then fails to compile */,

View File

@ -12,7 +12,6 @@ pub enum KeyCode {
escape = 27 escape = 27
space = 32 space = 32
backspace = 127 backspace = 127
exclamation = 33 exclamation = 33
double_quote = 34 double_quote = 34
hashtag = 35 hashtag = 35
@ -28,7 +27,6 @@ pub enum KeyCode {
minus = 45 minus = 45
period = 46 period = 46
slash = 47 slash = 47
_0 = 48 _0 = 48
_1 = 49 _1 = 49
_2 = 50 _2 = 50
@ -39,7 +37,6 @@ pub enum KeyCode {
_7 = 55 _7 = 55
_8 = 56 _8 = 56
_9 = 57 _9 = 57
colon = 58 colon = 58
semicolon = 59 semicolon = 59
less_than = 60 less_than = 60
@ -47,7 +44,6 @@ pub enum KeyCode {
greater_than = 62 greater_than = 62
question_mark = 63 question_mark = 63
at = 64 at = 64
a = 97 a = 97
b = 98 b = 98
c = 99 c = 99
@ -74,19 +70,16 @@ pub enum KeyCode {
x = 120 x = 120
y = 121 y = 121
z = 122 z = 122
left_square_bracket = 91 left_square_bracket = 91
backslash = 92 backslash = 92
right_square_bracket = 93 right_square_bracket = 93
caret = 94 caret = 94
underscore = 95 underscore = 95
backtick = 96 backtick = 96
left_curly_bracket = 123 left_curly_bracket = 123
vertical_bar = 124 vertical_bar = 124
right_curly_bracket = 125 right_curly_bracket = 125
tilde = 126 tilde = 126
insert = 260 insert = 260
delete = 261 delete = 261
up = 262 up = 262
@ -97,7 +90,6 @@ pub enum KeyCode {
page_down = 267 page_down = 267
home = 268 home = 268
end = 269 end = 269
f1 = 290 f1 = 290
f2 = 291 f2 = 291
f3 = 292 f3 = 292
@ -160,19 +152,16 @@ pub enum Modifiers {
pub struct Event { pub struct Event {
pub: pub:
typ EventType typ EventType
// Mouse event info // Mouse event info
x int x int
y int y int
button MouseButton button MouseButton
direction Direction direction Direction
// Keyboard event info // Keyboard event info
code KeyCode code KeyCode
modifiers Modifiers modifiers Modifiers
ascii byte ascii byte
utf8 string utf8 string
// Resized event info // Resized event info
width int width int
height int height int
@ -211,7 +200,9 @@ pub struct Config {
use_alternate_buffer bool = true use_alternate_buffer bool = true
skip_init_checks bool skip_init_checks bool
// All kill signals to set up exit listeners on: // All kill signals to set up exit listeners on:
reset []os.Signal = [.hup, .int, .quit, .ill, .abrt, .bus, .fpe, .kill, .segv, .pipe, .alrm, .term, .stop] reset []os.Signal = [.hup, .int, .quit, .ill, .abrt, .bus, .fpe, .kill, .segv, .pipe, .alrm, .term,
.stop,
]
} }
[inline] [inline]

View File

@ -142,7 +142,12 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
for embed in node.embeds { for embed in node.embeds {
f.mark_types_import_as_used(embed.typ) f.mark_types_import_as_used(embed.typ)
styp := f.table.type_to_str_using_aliases(embed.typ, f.mod2alias) styp := f.table.type_to_str_using_aliases(embed.typ, f.mod2alias)
if embed.comments.len == 0 {
f.writeln('\t$styp') f.writeln('\t$styp')
} else {
f.write('\t$styp')
f.comments(embed.comments, level: .indent)
}
} }
mut field_align_i := 0 mut field_align_i := 0
mut comment_align_i := 0 mut comment_align_i := 0

View File

@ -5,13 +5,14 @@ struct Foo {
struct Test {} struct Test {}
struct Bar { struct Bar {
Foo Foo // comment for Foo
Test Test // comment for Test
// another comment for Test
y int y int
z string z string
} }
struct Baz { struct Baz {
Foo Foo // Another comment for Foo
Test Test
} }

View File

@ -187,12 +187,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
// struct embedding // struct embedding
type_pos = p.tok.position() type_pos = p.tok.position()
typ = p.parse_type() typ = p.parse_type()
for p.tok.kind == .comment { ecomments := p.eat_comments({})
comments << p.comment()
if p.tok.kind == .rcbr {
break
}
}
type_pos = type_pos.extend(p.prev_tok.position()) type_pos = type_pos.extend(p.prev_tok.position())
if !is_on_top { if !is_on_top {
p.error_with_pos('struct embedding must be declared at the beginning of the struct body', p.error_with_pos('struct embedding must be declared at the beginning of the struct body',
@ -214,6 +209,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
embeds << ast.Embed{ embeds << ast.Embed{
typ: typ typ: typ
pos: type_pos pos: type_pos
comments: ecomments
} }
} else { } else {
// struct field // struct field

View File

@ -94,11 +94,11 @@ fn test_inttypes_string_interpolation() {
i := -1622999040 // -0x60BD 0000 i := -1622999040 // -0x60BD 0000
ui := u32(3421958087) // 0xCBF6 EFC7 ui := u32(3421958087) // 0xCBF6 EFC7
vp := voidptr(ui) vp := voidptr(ui)
mut bp := byteptr(0) mut bp := &byte(0)
$if x64 { $if x64 {
bp = byteptr(15541149836) // 0x3 9E53 208C bp = &byte(15541149836) // 0x3 9E53 208C
} $else { } $else {
bp = byteptr(3541149836) // 0xD311 A88C bp = &byte(3541149836) // 0xD311 A88C
} }
l := i64(-7694555558525237396) l := i64(-7694555558525237396)
ul := u64(17234006112912956370) ul := u64(17234006112912956370)