Skip to content

Commit c2e8f0b

Browse files
committed
add trailing commas in arrays, dictionaries and enums
1 parent 0fc7dba commit c2e8f0b

6 files changed

Lines changed: 115 additions & 3 deletions

File tree

queries/gdscript.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
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
(pair ":" @append_space)
39+
(dictionary ((pair (_expression)) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "}") (#multi_line_only!))
3840

3941
; FUNCTIONS
4042
(function_definition (name) @append_antispace)
@@ -83,6 +85,7 @@
8385
"{" @append_input_softline @append_indent_start
8486
"}" @prepend_input_softline @prepend_indent_end)
8587
(enumerator_list "," @append_spaced_softline . (comment)? @do_nothing)
88+
(enumerator_list ((enumerator) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "}") (#multi_line_only!))
8689
(enumerator_list) @prepend_space
8790

8891
; 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/trailing_comma.gd

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

tests/input/trailing_comma.gd

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

0 commit comments

Comments
 (0)