Skip to content

Commit 16615e1

Browse files
committed
Fix method call chain with long list of arguments in a call in the
middle causing line continuation (\) marks Fix #298
1 parent 69e65fa commit 16615e1

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎src/formatter.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,12 @@ fn process_method_call_arguments(
26572657
} else if has_lambda_argument {
26582658
process_node(input, args, render_elements);
26592659
} else {
2660+
// Prevent a multiline argument list from forcing the surrounding
2661+
// method call chain to use explicit line continuations (trailing
2662+
// "\").
2663+
let group_index = begin_group_until_first_line_break(render_elements);
26602664
process_method_arguments_flat(input, args, render_elements);
2665+
finish_group(render_elements, group_index);
26612666
}
26622667
}
26632668
}

‎tests/expected/func_multiline_calls.gd‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ func play_tween_jump() -> void:
5757
.tween_property(animated_sprite, "scale", Vector2(1.2, 0.8), 0.1) \
5858
.set_ease(Tween.EASE_OUT) \
5959
.set_trans(Tween.TRANS_BACK)
60+
61+
62+
# A multiline argument in a function call that's not at the end of a chain of
63+
# function calls should not force explicit line continuations for the rest of a
64+
# chain. In a previous version it would break like
65+
#
66+
# S \
67+
# .declare(
68+
func issue_298() -> void:
69+
S.declare([
70+
S.bind_label(item_name, title),
71+
S.bind_label(item_description, description),
72+
S.bind_label(cost, cost_label),
73+
S.bind_label(buy_switch_text, buy_or_switch_label),
74+
S.bind_visible(active, self),
75+
S.bind_visible(should_show_cost, cost_container),
76+
]).bind(self)

‎tests/input/func_multiline_calls.gd‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,20 @@ func _test() -> void:
4141
# (trailing '\').
4242
func play_tween_jump() -> void:
4343
create_tween().tween_property(animated_sprite, "scale", Vector2(1.2, 0.8), 0.1).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)
44+
45+
46+
# A multiline argument in a function call that's not at the end of a chain of
47+
# function calls should not force explicit line continuations for the rest of a
48+
# chain. In a previous version it would break like
49+
#
50+
# S \
51+
# .declare(
52+
func issue_298() -> void:
53+
S.declare([
54+
S.bind_label(item_name, title),
55+
S.bind_label(item_description, description),
56+
S.bind_label(cost, cost_label),
57+
S.bind_label(buy_switch_text, buy_or_switch_label),
58+
S.bind_visible(active, self),
59+
S.bind_visible(should_show_cost, cost_container),
60+
]).bind(self)

0 commit comments

Comments
 (0)