mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: fix chain calls with comments (#14470)
This commit is contained in:
parent
11bdb04d0c
commit
bf44572f30
@ -1639,6 +1639,7 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
|
|||||||
for arg in node.args {
|
for arg in node.args {
|
||||||
f.comments(arg.comments)
|
f.comments(arg.comments)
|
||||||
}
|
}
|
||||||
|
mut is_method_newline := false
|
||||||
if node.is_method {
|
if node.is_method {
|
||||||
if node.name in ['map', 'filter', 'all', 'any'] {
|
if node.name in ['map', 'filter', 'all', 'any'] {
|
||||||
f.in_lambda_depth++
|
f.in_lambda_depth++
|
||||||
@ -1658,6 +1659,11 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.expr(node.left)
|
f.expr(node.left)
|
||||||
|
is_method_newline = node.left.pos().last_line != node.name_pos.line_nr
|
||||||
|
if is_method_newline {
|
||||||
|
f.indent++
|
||||||
|
f.writeln('')
|
||||||
|
}
|
||||||
f.write('.' + node.name)
|
f.write('.' + node.name)
|
||||||
} else {
|
} else {
|
||||||
f.write_language_prefix(node.language)
|
f.write_language_prefix(node.language)
|
||||||
@ -1680,6 +1686,9 @@ 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.comments(node.comments, has_nl: false)
|
||||||
|
if is_method_newline {
|
||||||
|
f.indent--
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut f Fmt) write_generic_call_if_require(node ast.CallExpr) {
|
fn (mut f Fmt) write_generic_call_if_require(node ast.CallExpr) {
|
||||||
|
10
vlib/v/fmt/tests/chain_calls_with_comments_expected.vv
Normal file
10
vlib/v/fmt/tests/chain_calls_with_comments_expected.vv
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fn main() {
|
||||||
|
options := cmdline
|
||||||
|
.only_options(args)
|
||||||
|
.filter(it != '-') // options, not including '-'
|
||||||
|
.map(if it.bytes().len > 1 {
|
||||||
|
1
|
||||||
|
})
|
||||||
|
|
||||||
|
println(options)
|
||||||
|
}
|
10
vlib/v/fmt/tests/chain_calls_with_comments_input.vv
Normal file
10
vlib/v/fmt/tests/chain_calls_with_comments_input.vv
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fn main() {
|
||||||
|
options := cmdline
|
||||||
|
.only_options(args)
|
||||||
|
.filter(it != '-') // options, not including '-'
|
||||||
|
.map(if it.bytes().len>1{
|
||||||
|
1
|
||||||
|
})
|
||||||
|
|
||||||
|
println(options)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user