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/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/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` */
]
vfmt_verify_list = [
@ -43,7 +42,6 @@ const (
'vlib/',
]
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/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 */,

View File

@ -6,122 +6,114 @@ module ui
import os
pub enum KeyCode {
null = 0
tab = 9
enter = 10
escape = 27
space = 32
backspace = 127
exclamation = 33
double_quote = 34
hashtag = 35
dollar = 36
percent = 37
ampersand = 38
single_quote = 39
left_paren = 40
right_paren = 41
asterisk = 42
plus = 43
comma = 44
minus = 45
period = 46
slash = 47
_0 = 48
_1 = 49
_2 = 50
_3 = 51
_4 = 52
_5 = 53
_6 = 54
_7 = 55
_8 = 56
_9 = 57
colon = 58
semicolon = 59
less_than = 60
equal = 61
greater_than = 62
question_mark = 63
at = 64
a = 97
b = 98
c = 99
d = 100
e = 101
f = 102
g = 103
h = 104
i = 105
j = 106
k = 107
l = 108
m = 109
n = 110
o = 111
p = 112
q = 113
r = 114
s = 115
t = 116
u = 117
v = 118
w = 119
x = 120
y = 121
z = 122
left_square_bracket = 91
backslash = 92
null = 0
tab = 9
enter = 10
escape = 27
space = 32
backspace = 127
exclamation = 33
double_quote = 34
hashtag = 35
dollar = 36
percent = 37
ampersand = 38
single_quote = 39
left_paren = 40
right_paren = 41
asterisk = 42
plus = 43
comma = 44
minus = 45
period = 46
slash = 47
_0 = 48
_1 = 49
_2 = 50
_3 = 51
_4 = 52
_5 = 53
_6 = 54
_7 = 55
_8 = 56
_9 = 57
colon = 58
semicolon = 59
less_than = 60
equal = 61
greater_than = 62
question_mark = 63
at = 64
a = 97
b = 98
c = 99
d = 100
e = 101
f = 102
g = 103
h = 104
i = 105
j = 106
k = 107
l = 108
m = 109
n = 110
o = 111
p = 112
q = 113
r = 114
s = 115
t = 116
u = 117
v = 118
w = 119
x = 120
y = 121
z = 122
left_square_bracket = 91
backslash = 92
right_square_bracket = 93
caret = 94
underscore = 95
backtick = 96
left_curly_bracket = 123
vertical_bar = 124
right_curly_bracket = 125
tilde = 126
insert = 260
delete = 261
up = 262
down = 263
right = 264
left = 265
page_up = 266
page_down = 267
home = 268
end = 269
f1 = 290
f2 = 291
f3 = 292
f4 = 293
f5 = 294
f6 = 295
f7 = 296
f8 = 297
f9 = 298
f10 = 299
f11 = 300
f12 = 301
f13 = 302
f14 = 303
f15 = 304
f16 = 305
f17 = 306
f18 = 307
f19 = 308
f20 = 309
f21 = 310
f22 = 311
f23 = 312
f24 = 313
caret = 94
underscore = 95
backtick = 96
left_curly_bracket = 123
vertical_bar = 124
right_curly_bracket = 125
tilde = 126
insert = 260
delete = 261
up = 262
down = 263
right = 264
left = 265
page_up = 266
page_down = 267
home = 268
end = 269
f1 = 290
f2 = 291
f3 = 292
f4 = 293
f5 = 294
f6 = 295
f7 = 296
f8 = 297
f9 = 298
f10 = 299
f11 = 300
f12 = 301
f13 = 302
f14 = 303
f15 = 304
f16 = 305
f17 = 306
f18 = 307
f19 = 308
f20 = 309
f21 = 310
f22 = 311
f23 = 312
f24 = 313
}
pub enum Direction {
@ -159,34 +151,31 @@ pub enum Modifiers {
pub struct Event {
pub:
typ EventType
typ EventType
// Mouse event info
x int
y int
button MouseButton
direction Direction
// Keyboard event info
code KeyCode
modifiers Modifiers
ascii byte
utf8 string
// Resized event info
width int
height int
width int
height int
}
pub struct Context {
ExtraContext // contains fields specific to an implementation
pub:
cfg Config // adsasdas
cfg Config // adsasdas
mut:
print_buf []byte
paused bool
enable_su bool
enable_rgb bool
print_buf []byte
paused bool
enable_su bool
enable_rgb bool
pub mut:
frame_count u64
window_width int
@ -194,16 +183,16 @@ pub mut:
}
pub struct Config {
user_data voidptr
init_fn fn(voidptr)
frame_fn fn(voidptr)
cleanup_fn fn(voidptr)
event_fn fn(&Event, voidptr)
fail_fn fn(string)
user_data voidptr
init_fn fn (voidptr)
frame_fn fn (voidptr)
cleanup_fn fn (voidptr)
event_fn fn (&Event, voidptr)
fail_fn fn (string)
buffer_size int = 256
frame_rate int = 30
use_x11 bool
buffer_size int = 256
frame_rate int = 30
use_x11 bool
window_title string
hide_cursor bool
@ -211,7 +200,9 @@ pub struct Config {
use_alternate_buffer bool = true
skip_init_checks bool
// 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]

View File

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

View File

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

View File

@ -187,12 +187,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
// struct embedding
type_pos = p.tok.position()
typ = p.parse_type()
for p.tok.kind == .comment {
comments << p.comment()
if p.tok.kind == .rcbr {
break
}
}
ecomments := p.eat_comments({})
type_pos = type_pos.extend(p.prev_tok.position())
if !is_on_top {
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{
typ: typ
pos: type_pos
comments: ecomments
}
} else {
// struct field

View File

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