diff --git a/queries/gdscript.scm b/queries/gdscript.scm index ffa5063..d33684b 100644 --- a/queries/gdscript.scm +++ b/queries/gdscript.scm @@ -29,12 +29,14 @@ "[" @append_empty_softline @append_indent_start "]" @prepend_empty_softline @append_empty_softline @prepend_indent_end) (array "," @append_spaced_softline . (comment)? @do_nothing) +(array ((_expression) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "]") (#multi_line_only!)) (dictionary "{" @append_empty_softline @append_indent_start "}" @prepend_empty_softline @append_empty_softline @prepend_indent_end) (dictionary "," @append_spaced_softline . (comment)? @do_nothing) (pair ":" @append_space) +(dictionary ((pair (_expression)) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "}") (#multi_line_only!)) ; FUNCTIONS (function_definition (name) @append_antispace) @@ -56,6 +58,7 @@ "(" @append_hardline @append_indent_start ")" @prepend_hardline @prepend_indent_end (#multi_line_only!)) +(arguments ((_expression) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . ")") (#multi_line_only!)) ; MULTI-LINE PARAMETERS (in function definitions) (parameters @@ -65,6 +68,7 @@ (parameters ([(typed_parameter) (typed_default_parameter) (identifier) (default_parameter)]) @prepend_hardline @prepend_indent_start @append_indent_end (#multi_line_only!)) +(parameters (([(typed_parameter) (typed_default_parameter) (identifier) (default_parameter)]) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . ")") (#multi_line_only!)) ; CLASS DEFINITIONS (class_definition (body) @prepend_hardline) @@ -83,6 +87,7 @@ "{" @append_input_softline @append_indent_start "}" @prepend_input_softline @prepend_indent_end) (enumerator_list "," @append_spaced_softline . (comment)? @do_nothing) +(enumerator_list ((enumerator) @append_delimiter (#delimiter! ",") . ","? @do_nothing . (comment)? . "}") (#multi_line_only!)) (enumerator_list) @prepend_space ; CONSTRUCTORS diff --git a/tests/expected/array_long_strings.gd b/tests/expected/array_long_strings.gd index d599a66..377c1e2 100644 --- a/tests/expected/array_long_strings.gd +++ b/tests/expected/array_long_strings.gd @@ -3,5 +3,5 @@ var dialogue_items: Array[String] = [ "...and it is a little bit complicated.", "Let's see if I got it right: an array is a list of values!", "Did I get it right? Did I?", - "Hehe! Bye bye~!" + "Hehe! Bye bye~!", ] diff --git a/tests/expected/comments_inline.gd b/tests/expected/comments_inline.gd index 11fcbb1..9fb09b4 100644 --- a/tests/expected/comments_inline.gd +++ b/tests/expected/comments_inline.gd @@ -8,7 +8,7 @@ var prop = 10: # var comment enum Foo { A, # Comment B, # Comment - C + C, } diff --git a/tests/expected/enums.gd b/tests/expected/enums.gd index 71cfc62..4abaf1e 100644 --- a/tests/expected/enums.gd +++ b/tests/expected/enums.gd @@ -10,7 +10,7 @@ enum ThirdEnum { Eeeeee, Ffffff, Gggggg, - Hhhhhh + Hhhhhh, } diff --git a/tests/expected/func_args_multiline.gd b/tests/expected/func_args_multiline.gd index 1990e98..2254cb4 100644 --- a/tests/expected/func_args_multiline.gd +++ b/tests/expected/func_args_multiline.gd @@ -2,7 +2,7 @@ func test( a: int, b: String, c, - d = 42 + d = 42, ) -> void: pass diff --git a/tests/expected/func_constructor_args_multiline.gd b/tests/expected/func_constructor_args_multiline.gd index 657036e..be9427d 100644 --- a/tests/expected/func_constructor_args_multiline.gd +++ b/tests/expected/func_constructor_args_multiline.gd @@ -1,7 +1,7 @@ func _init( init_mob: Mob3D, init_spawning_point: Node3D, - init_projectile_scene: PackedScene + init_projectile_scene: PackedScene, ) -> void: pass diff --git a/tests/expected/func_multiline_calls.gd b/tests/expected/func_multiline_calls.gd index 4bf444a..0983dba 100644 --- a/tests/expected/func_multiline_calls.gd +++ b/tests/expected/func_multiline_calls.gd @@ -2,13 +2,13 @@ func test(): print( "Testing", "multiline", - "print" + "print", ) print( "Testing", "multiline", - "print" + "print", ) print("Testing", "multiline", "print") @@ -16,11 +16,11 @@ func test(): print( "Testing", "multiline", - "print" + "print", ) print( "Testing", "multiline", - "print" + "print", ) diff --git a/tests/expected/trailing_comma.gd b/tests/expected/trailing_comma.gd new file mode 100644 index 0000000..242a828 --- /dev/null +++ b/tests/expected/trailing_comma.gd @@ -0,0 +1,62 @@ +var a = [ + 1, + 2, + 3, +] + +var aa = [1, 2, 3] + +var b = [ + 1, + 2, + 3, # comment +] + +var c = { + "a": 1, + "b": 2, + "c": 3, # comment +} + +var d = { + "a": 1, + "b": 2, + "c": 3, +} + +var dd = {"a": 1, "b": 2, "c": 3} + +enum Foo { + A, + B, + C, +} + +enum Foo2 { + A, + B, + C, # comment +} + +enum Foo3 { A, B, C } + + +func foo( + a, + b, +): + pass + + +func bar( + a, + b, # comment +): + pass + + +func f(): + foo( + 1, + 2, + ) diff --git a/tests/input/trailing_comma.gd b/tests/input/trailing_comma.gd new file mode 100644 index 0000000..a882420 --- /dev/null +++ b/tests/input/trailing_comma.gd @@ -0,0 +1,61 @@ +var a = [ + 1, + 2, + 3 +] + +var aa = [1, 2, 3] + +var b = [ + 1, + 2, + 3 # comment +] + +var c = { + "a": 1, + "b": 2, + "c": 3 # comment +} + +var d = { + "a": 1, + "b": 2, + "c": 3 +} + +var dd = {"a": 1, "b": 2, "c": 3} + +enum Foo { + A, + B, + C +} + +enum Foo2 { + A, + B, + C # comment +} + +enum Foo3 {A, B, C} + +func foo( + a, + b +): + pass + + +func bar( + a, + b # comment +): + pass + + +func f(): + foo( + 1, + 2 + )