From ef6011b94c7a5702fcb4e565f29107815fc8c08e Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Mon, 28 Dec 2020 14:38:21 +0100 Subject: [PATCH] fmt: keep comments after struct decl default value (#7648) --- vlib/v/fmt/tests/struct_default_field_expressions_keep.vv | 8 +++++++- vlib/v/parser/struct.v | 1 + vlib/x/websocket/websocket_client.v | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vlib/v/fmt/tests/struct_default_field_expressions_keep.vv b/vlib/v/fmt/tests/struct_default_field_expressions_keep.vv index 78e6852af6..0a2adaf4c0 100644 --- a/vlib/v/fmt/tests/struct_default_field_expressions_keep.vv +++ b/vlib/v/fmt/tests/struct_default_field_expressions_keep.vv @@ -1,8 +1,14 @@ struct Foo { - i int = 1 + i int = 1 // A comment } struct Bar { f Foo = &Foo(0) z int [skip] = -1 } + +struct Baz { + x int = 1 // It's one + y string = 'one' // It's one written out + z bool = true // Also one +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 2e1b19eea7..0af4d6e234 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -229,6 +229,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { else {} } has_default_expr = true + comments << p.eat_comments() } // TODO merge table and ast Fields? ast_fields << ast.StructField{ diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index 55fcb1dc51..9fcecdddc5 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -31,8 +31,7 @@ pub: id string // unique id of client pub mut: conn net.TcpConn // underlying TCP socket connection - // size of nounce used for masking - nonce_size int = 16 + nonce_size int = 16 // size of nounce used for masking panic_on_callback bool // set to true of callbacks can panic state State // current state of connection logger &log.Log // logger used to log messages