diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index f6b6bdf27e..699fb00b5a 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -363,6 +363,7 @@ pub mut: free_receiver bool // true if the receiver expression needs to be freed scope &Scope from_embed_type table.Type // holds the type of the embed that the method is called from + comments []Comment } /* diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 2ce1a3eed5..24710e744d 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1407,7 +1407,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { pub fn (mut f Fmt) comments(comments []ast.Comment, options CommentsOptions) { for i, c in comments { if !f.out.last_n(1)[0].is_space() { - f.write('\t') + f.write(' ') } if options.level == .indent { f.indent++ @@ -1723,6 +1723,7 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) { f.write(')') f.or_expr(node.or_block) } + f.comments(node.comments, has_nl: false) f.use_short_fn_args = old_short_arg_state } diff --git a/vlib/v/fmt/tests/comments_keep.vv b/vlib/v/fmt/tests/comments_keep.vv index ceb0db0c85..9f1d287f02 100644 --- a/vlib/v/fmt/tests/comments_keep.vv +++ b/vlib/v/fmt/tests/comments_keep.vv @@ -43,4 +43,5 @@ fn main() { ////// // / // 123 + println('hello world') } diff --git a/vlib/v/fmt/tests/vscript_keep.vv b/vlib/v/fmt/tests/vscript_keep.vv index 372986bc5b..24cf41dca4 100644 --- a/vlib/v/fmt/tests/vscript_keep.vv +++ b/vlib/v/fmt/tests/vscript_keep.vv @@ -1,4 +1,7 @@ #!/usr/local/bin/v run x := 5 -println(x) +println(x) // comment after +println('b') +// comment between +println('c') diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 20e9bbe543..a53469d60c 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -92,6 +92,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp if fn_name in p.imported_symbols { fn_name = p.imported_symbols[fn_name] } + comments := p.eat_line_end_comments() return ast.CallExpr{ name: fn_name args: args @@ -106,6 +107,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp pos: or_pos } scope: p.scope + comments: comments } }