From c2e8f0bb2468674d069ccb46966777dea32beb8f Mon Sep 17 00:00:00 2001 From: Nesterov Nikita Date: Fri, 19 Sep 2025 13:56:36 +0300 Subject: [PATCH 1/3] add trailing commas in arrays, dictionaries and enums --- queries/gdscript.scm | 3 ++ tests/expected/array_long_strings.gd | 2 +- tests/expected/comments_inline.gd | 2 +- tests/expected/enums.gd | 2 +- tests/expected/trailing_comma.gd | 55 ++++++++++++++++++++++++++++ tests/input/trailing_comma.gd | 54 +++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 tests/expected/trailing_comma.gd create mode 100644 tests/input/trailing_comma.gd diff --git a/queries/gdscript.scm b/queries/gdscript.scm index ffa5063..9c2798f 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) @@ -83,6 +85,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/trailing_comma.gd b/tests/expected/trailing_comma.gd new file mode 100644 index 0000000..c8a3d51 --- /dev/null +++ b/tests/expected/trailing_comma.gd @@ -0,0 +1,55 @@ +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 diff --git a/tests/input/trailing_comma.gd b/tests/input/trailing_comma.gd new file mode 100644 index 0000000..c64846f --- /dev/null +++ b/tests/input/trailing_comma.gd @@ -0,0 +1,54 @@ +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 From f15edcb5a81d7eca73ce21769e9923101e170362 Mon Sep 17 00:00:00 2001 From: Nesterov Nikita Date: Fri, 19 Sep 2025 13:56:55 +0300 Subject: [PATCH 2/3] add trailing commas in parameters (in func definition) --- queries/gdscript.scm | 1 + tests/expected/func_args_multiline.gd | 2 +- tests/expected/func_constructor_args_multiline.gd | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/queries/gdscript.scm b/queries/gdscript.scm index 9c2798f..d6935b6 100644 --- a/queries/gdscript.scm +++ b/queries/gdscript.scm @@ -67,6 +67,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) 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 From 33ca2a2541fa46017aca9494034567eb94c1511e Mon Sep 17 00:00:00 2001 From: Nesterov Nikita Date: Fri, 19 Sep 2025 14:05:17 +0300 Subject: [PATCH 3/3] add trailing commas in function calls --- queries/gdscript.scm | 1 + tests/expected/func_multiline_calls.gd | 8 ++++---- tests/expected/trailing_comma.gd | 7 +++++++ tests/input/trailing_comma.gd | 7 +++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/queries/gdscript.scm b/queries/gdscript.scm index d6935b6..d33684b 100644 --- a/queries/gdscript.scm +++ b/queries/gdscript.scm @@ -58,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 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 index c8a3d51..242a828 100644 --- a/tests/expected/trailing_comma.gd +++ b/tests/expected/trailing_comma.gd @@ -53,3 +53,10 @@ func bar( b, # comment ): pass + + +func f(): + foo( + 1, + 2, + ) diff --git a/tests/input/trailing_comma.gd b/tests/input/trailing_comma.gd index c64846f..a882420 100644 --- a/tests/input/trailing_comma.gd +++ b/tests/input/trailing_comma.gd @@ -52,3 +52,10 @@ func bar( b # comment ): pass + + +func f(): + foo( + 1, + 2 + )