Skip to content

Commit 143d76a

Browse files
committed
Add support for line breaks in chained function calls
Close #217
1 parent 1151b30 commit 143d76a

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

queries/gdscript.scm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161

6262
; MULTI-LINE ARGUMENTS (in function calls)
6363
(arguments "," @append_hardline . (comment)? @do_nothing (#multi_line_only!))
64-
; uncomment for double indentation in multiline function calls
65-
; (arguments (_) @prepend_indent_start @append_indent_end)
6664
(arguments
6765
"(" @append_hardline @append_indent_start
6866
")" @prepend_hardline @prepend_indent_end
@@ -106,6 +104,9 @@
106104
(constructor_definition (body) @prepend_hardline)
107105

108106
; OPERATORS
107+
; Preserve user-inserted line breaks in chained attribute/method calls.
108+
(attribute "." @prepend_input_softline @prepend_antispace)
109+
109110
; Allow line breaks around binary operators for long expressions
110111
; This means that if the programmer has a long expression, they can break it up by wrapping something on a line
111112
(binary_operator

tests/expected/issue_217.gd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Based on https://github.com/GDQuest/GDScript-formatter/issues/217
2+
func _test() -> void:
3+
print(
4+
"ABCDEF"
5+
.replace("A", "111111111111111111111111111111111111111111111111")
6+
.replace("B", "2")
7+
.replace("C", "3"),
8+
)
9+
10+
foo(
11+
"ABCDEF"
12+
.replace(
13+
"A",
14+
"111111111111111111111111111111111111111111111111",
15+
)
16+
.replace("B", "2")
17+
.replace("C", "3"),
18+
"second argument",
19+
)

tests/input/issue_217.gd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Based on https://github.com/GDQuest/GDScript-formatter/issues/217
2+
func _test() -> void:
3+
print("ABCDEF"
4+
.replace("A", "111111111111111111111111111111111111111111111111")
5+
.replace("B", "2")
6+
.replace("C", "3"))
7+
8+
foo(
9+
"ABCDEF"
10+
.replace(
11+
"A",
12+
"111111111111111111111111111111111111111111111111"
13+
)
14+
.replace("B", "2")
15+
.replace("C", "3"),
16+
"second argument"
17+
)

0 commit comments

Comments
 (0)