Skip to content

Commit 4e3830d

Browse files
authored
Merge pull request #46 from shadr/add-trailing-commas
Add trailing commas (closes #37)
2 parents d6f5202 + 33ca2a2 commit 4e3830d

9 files changed

Lines changed: 137 additions & 9 deletions

queries/gdscript.scm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
"[" @append_empty_softline @append_indent_start
3030
"]" @prepend_empty_softline @append_empty_softline @prepend_indent_end)
3131
(array "," @append_spaced_softline . (comment)? @do_nothing)
32+
(array ((_expression) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "]") (#multi_line_only!))
3233

3334
(dictionary
3435
"{" @append_empty_softline @append_indent_start
3536
"}" @prepend_empty_softline @append_empty_softline @prepend_indent_end)
3637
(dictionary "," @append_spaced_softline . (comment)? @do_nothing)
3738
(dictionary "{" @append_space "}" @prepend_space (#single_line_only!))
3839
(pair ":" @append_space)
40+
(dictionary ((pair (_expression)) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "}") (#multi_line_only!))
3941

4042
; FUNCTIONS
4143
(function_definition (name) @append_antispace)
@@ -57,6 +59,7 @@
5759
"(" @append_hardline @append_indent_start
5860
")" @prepend_hardline @prepend_indent_end
5961
(#multi_line_only!))
62+
(arguments ((_expression) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . ")") (#multi_line_only!))
6063

6164
; MULTI-LINE PARAMETERS (in function definitions)
6265
(parameters
@@ -66,6 +69,7 @@
6669
(parameters
6770
([(typed_parameter) (typed_default_parameter) (identifier) (default_parameter)]) @prepend_hardline @prepend_indent_start @append_indent_end
6871
(#multi_line_only!))
72+
(parameters (([(typed_parameter) (typed_default_parameter) (identifier) (default_parameter)]) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . ")") (#multi_line_only!))
6973

7074
; CLASS DEFINITIONS
7175
(class_definition (body) @prepend_hardline)
@@ -84,6 +88,7 @@
8488
"{" @append_input_softline @append_indent_start
8589
"}" @prepend_input_softline @prepend_indent_end)
8690
(enumerator_list "," @append_spaced_softline . (comment)? @do_nothing)
91+
(enumerator_list ((enumerator) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "}") (#multi_line_only!))
8792
(enumerator_list) @prepend_space
8893

8994
; CONSTRUCTORS

tests/expected/array_long_strings.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ var dialogue_items: Array[String] = [
33
"...and it is a little bit complicated.",
44
"Let's see if I got it right: an array is a list of values!",
55
"Did I get it right? Did I?",
6-
"Hehe! Bye bye~!"
6+
"Hehe! Bye bye~!",
77
]

tests/expected/comments_inline.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var prop = 10: # var comment
88
enum Foo {
99
A, # Comment
1010
B, # Comment
11-
C
11+
C,
1212
}
1313

1414

tests/expected/enums.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum ThirdEnum {
1010
Eeeeee,
1111
Ffffff,
1212
Gggggg,
13-
Hhhhhh
13+
Hhhhhh,
1414
}
1515

1616

tests/expected/func_args_multiline.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ func test(
22
a: int,
33
b: String,
44
c,
5-
d = 42
5+
d = 42,
66
) -> void:
77
pass
88

tests/expected/func_constructor_args_multiline.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
func _init(
22
init_mob: Mob3D,
33
init_spawning_point: Node3D,
4-
init_projectile_scene: PackedScene
4+
init_projectile_scene: PackedScene,
55
) -> void:
66
pass
77

tests/expected/func_multiline_calls.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ func test():
22
print(
33
"Testing",
44
"multiline",
5-
"print"
5+
"print",
66
)
77

88
print(
99
"Testing",
1010
"multiline",
11-
"print"
11+
"print",
1212
)
1313

1414
print("Testing", "multiline", "print")
1515

1616
print(
1717
"Testing",
1818
"multiline",
19-
"print"
19+
"print",
2020
)
2121

2222
print(
2323
"Testing",
2424
"multiline",
25-
"print"
25+
"print",
2626
)

tests/expected/trailing_comma.gd

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var a = [
2+
1,
3+
2,
4+
3,
5+
]
6+
7+
var aa = [1, 2, 3]
8+
9+
var b = [
10+
1,
11+
2,
12+
3, # comment
13+
]
14+
15+
var c = {
16+
"a": 1,
17+
"b": 2,
18+
"c": 3, # comment
19+
}
20+
21+
var d = {
22+
"a": 1,
23+
"b": 2,
24+
"c": 3,
25+
}
26+
27+
var dd = {"a": 1, "b": 2, "c": 3}
28+
29+
enum Foo {
30+
A,
31+
B,
32+
C,
33+
}
34+
35+
enum Foo2 {
36+
A,
37+
B,
38+
C, # comment
39+
}
40+
41+
enum Foo3 { A, B, C }
42+
43+
44+
func foo(
45+
a,
46+
b,
47+
):
48+
pass
49+
50+
51+
func bar(
52+
a,
53+
b, # comment
54+
):
55+
pass
56+
57+
58+
func f():
59+
foo(
60+
1,
61+
2,
62+
)

tests/input/trailing_comma.gd

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var a = [
2+
1,
3+
2,
4+
3
5+
]
6+
7+
var aa = [1, 2, 3]
8+
9+
var b = [
10+
1,
11+
2,
12+
3 # comment
13+
]
14+
15+
var c = {
16+
"a": 1,
17+
"b": 2,
18+
"c": 3 # comment
19+
}
20+
21+
var d = {
22+
"a": 1,
23+
"b": 2,
24+
"c": 3
25+
}
26+
27+
var dd = {"a": 1, "b": 2, "c": 3}
28+
29+
enum Foo {
30+
A,
31+
B,
32+
C
33+
}
34+
35+
enum Foo2 {
36+
A,
37+
B,
38+
C # comment
39+
}
40+
41+
enum Foo3 {A, B, C}
42+
43+
func foo(
44+
a,
45+
b
46+
):
47+
pass
48+
49+
50+
func bar(
51+
a,
52+
b # comment
53+
):
54+
pass
55+
56+
57+
func f():
58+
foo(
59+
1,
60+
2
61+
)

0 commit comments

Comments
 (0)