fmt: fix chain calls with comments (#14470)
parent
b15f50e9b1
commit
d79fdc075d
|
@ -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) {
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -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