fmt: keep comments after call_expr in vscript (#7990)

pull/7996/head
Lukas Neubert 2021-01-09 22:47:33 +01:00 committed by GitHub
parent 561d4f84b3
commit e79695e8fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 2 deletions

View File

@ -363,6 +363,7 @@ pub mut:
free_receiver bool // true if the receiver expression needs to be freed free_receiver bool // true if the receiver expression needs to be freed
scope &Scope scope &Scope
from_embed_type table.Type // holds the type of the embed that the method is called from from_embed_type table.Type // holds the type of the embed that the method is called from
comments []Comment
} }
/* /*

View File

@ -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) { pub fn (mut f Fmt) comments(comments []ast.Comment, options CommentsOptions) {
for i, c in comments { for i, c in comments {
if !f.out.last_n(1)[0].is_space() { if !f.out.last_n(1)[0].is_space() {
f.write('\t') f.write(' ')
} }
if options.level == .indent { if options.level == .indent {
f.indent++ f.indent++
@ -1723,6 +1723,7 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
f.write(')') f.write(')')
f.or_expr(node.or_block) f.or_expr(node.or_block)
} }
f.comments(node.comments, has_nl: false)
f.use_short_fn_args = old_short_arg_state f.use_short_fn_args = old_short_arg_state
} }

View File

@ -43,4 +43,5 @@ fn main() {
////// //////
// / // /
// 123 // 123
println('hello world')
} }

View File

@ -1,4 +1,7 @@
#!/usr/local/bin/v run #!/usr/local/bin/v run
x := 5 x := 5
println(x) println(x) // comment after
println('b')
// comment between
println('c')

View File

@ -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 { if fn_name in p.imported_symbols {
fn_name = p.imported_symbols[fn_name] fn_name = p.imported_symbols[fn_name]
} }
comments := p.eat_line_end_comments()
return ast.CallExpr{ return ast.CallExpr{
name: fn_name name: fn_name
args: args args: args
@ -106,6 +107,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp
pos: or_pos pos: or_pos
} }
scope: p.scope scope: p.scope
comments: comments
} }
} }