Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions queries/gdscript.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/array_long_strings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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~!",
]
2 changes: 1 addition & 1 deletion tests/expected/comments_inline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var prop = 10: # var comment
enum Foo {
A, # Comment
B, # Comment
C
C,
}


Expand Down
2 changes: 1 addition & 1 deletion tests/expected/enums.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum ThirdEnum {
Eeeeee,
Ffffff,
Gggggg,
Hhhhhh
Hhhhhh,
}


Expand Down
2 changes: 1 addition & 1 deletion tests/expected/func_args_multiline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ func test(
a: int,
b: String,
c,
d = 42
d = 42,
) -> void:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/expected/func_constructor_args_multiline.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
func _init(
init_mob: Mob3D,
init_spawning_point: Node3D,
init_projectile_scene: PackedScene
init_projectile_scene: PackedScene,
) -> void:
pass

Expand Down
8 changes: 4 additions & 4 deletions tests/expected/func_multiline_calls.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ func test():
print(
"Testing",
"multiline",
"print"
"print",
)

print(
"Testing",
"multiline",
"print"
"print",
)

print("Testing", "multiline", "print")

print(
"Testing",
"multiline",
"print"
"print",
)

print(
"Testing",
"multiline",
"print"
"print",
)
62 changes: 62 additions & 0 deletions tests/expected/trailing_comma.gd
Original file line number Diff line number Diff line change
@@ -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,
)
61 changes: 61 additions & 0 deletions tests/input/trailing_comma.gd
Original file line number Diff line number Diff line change
@@ -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
)