Unnamed repository; edit this file 'description' to name the repository.
Updated Godot support (#11235)
- update gdscript highlights - add godot-resource textobjects
Erasin Wang 2024-07-31
parent a4cfcff · commit b19551b
-rw-r--r--book/src/generated/lang-support.md2
-rw-r--r--languages.toml6
-rw-r--r--runtime/queries/gdscript/highlights.scm3
-rw-r--r--runtime/queries/gdscript/indents.scm1
-rw-r--r--runtime/queries/gdscript/textobjects.scm9
-rw-r--r--runtime/queries/godot-resource/injections.scm35
-rw-r--r--runtime/queries/godot-resource/textobjects.scm23
7 files changed, 74 insertions, 5 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 686dec5e..9c88b7a2 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -69,7 +69,7 @@
| glsl | ✓ | ✓ | ✓ | |
| gn | ✓ | | | |
| go | ✓ | ✓ | ✓ | `gopls`, `golangci-lint-langserver` |
-| godot-resource | ✓ | | | |
+| godot-resource | ✓ | ✓ | | |
| gomod | ✓ | | | `gopls` |
| gotmpl | ✓ | | | `gopls` |
| gowork | ✓ | | | `gopls` |
diff --git a/languages.toml b/languages.toml
index 0d268eec..2bd57abb 100644
--- a/languages.toml
+++ b/languages.toml
@@ -1995,12 +1995,12 @@ shebangs = []
roots = ["project.godot"]
auto-format = true
formatter = { command = "gdformat", args = ["-"] }
-comment-token = "#"
+comment-tokens = ["#", "##"]
indent = { tab-width = 4, unit = "\t" }
[[grammar]]
name = "gdscript"
-source = { git = "https://github.com/PrestonKnopp/tree-sitter-gdscript", rev = "a4b57cc3bcbfc24550e858159647e9238e7ad1ac" }
+source = { git = "https://github.com/PrestonKnopp/tree-sitter-gdscript", rev = "1f1e782fe2600f50ae57b53876505b8282388d77" }
[[language]]
name = "godot-resource"
@@ -2015,7 +2015,7 @@ indent = { tab-width = 4, unit = "\t" }
[[grammar]]
name = "godot-resource"
-source = { git = "https://github.com/PrestonKnopp/tree-sitter-godot-resource", rev = "b6ef0768711086a86b3297056f9ffb5cc1d77b4a" }
+source = { git = "https://github.com/PrestonKnopp/tree-sitter-godot-resource", rev = "2ffb90de47417018651fc3b970e5f6b67214dc9d" }
[[language]]
name = "nu"
diff --git a/runtime/queries/gdscript/highlights.scm b/runtime/queries/gdscript/highlights.scm
index 37aa3d62..fee67dc9 100644
--- a/runtime/queries/gdscript/highlights.scm
+++ b/runtime/queries/gdscript/highlights.scm
@@ -14,6 +14,7 @@
(attribute_call (identifier) @function)
(base_call (identifier) @function)
(call (identifier) @function)
+(lambda (name) @function)
; Function definitions
@@ -88,6 +89,7 @@
"<<"
">>"
":="
+ ":"
] @operator
(annotation (identifier) @keyword.storage.modifier)
@@ -97,6 +99,7 @@
"else"
"elif"
"match"
+ "when"
] @keyword.control.conditional
[
diff --git a/runtime/queries/gdscript/indents.scm b/runtime/queries/gdscript/indents.scm
index c969eb7c..3d49aec3 100644
--- a/runtime/queries/gdscript/indents.scm
+++ b/runtime/queries/gdscript/indents.scm
@@ -6,6 +6,7 @@
(pattern_section)
(function_definition)
+ (lambda)
(constructor_definition)
(class_definition)
(enum_definition)
diff --git a/runtime/queries/gdscript/textobjects.scm b/runtime/queries/gdscript/textobjects.scm
index 47512bba..3a2775fe 100644
--- a/runtime/queries/gdscript/textobjects.scm
+++ b/runtime/queries/gdscript/textobjects.scm
@@ -5,6 +5,8 @@
(function_definition
(body) @function.inside) @function.around
+(lambda (body) @function.inside) @function.around
+
(parameters
[
(identifier)
@@ -15,5 +17,12 @@
(arguments (_expression) @parameter.inside @parameter.around)
+[
+ (const_statement)
+ (variable_statement)
+ (pair)
+ (enumerator)
+] @entry.around
+
(comment) @comment.inside
(comment)+ @comment.around
diff --git a/runtime/queries/godot-resource/injections.scm b/runtime/queries/godot-resource/injections.scm
index 7929d63c..6e199f10 100644
--- a/runtime/queries/godot-resource/injections.scm
+++ b/runtime/queries/godot-resource/injections.scm
@@ -11,8 +11,41 @@
(property
(path) @_is_code
(string) @injection.content))
- (#match? @_type "type")
+ (#eq? @_type "type")
(#match? @_is_shader "Shader")
(#eq? @_is_code "code")
(#set! injection.language "glsl")
)
+
+((section
+ (identifier) @_is_resource
+ (property
+ (path) @_is_code
+ (string) @injection.content))
+ (#eq? @_is_resource "resource")
+ (#eq? @_is_code "code")
+ (#set! injection.language "glsl")
+)
+
+((section
+ (identifier) @_id
+ (property
+ (path) @_is_expression
+ (string) @injection.content))
+ (#eq? @_id "sub_resource")
+ (#eq? @_is_expression "expression")
+ (#set! injection.language "glsl")
+)
+
+((section
+ (attribute
+ (identifier) @_type
+ (string) @_is_shader)
+ (property
+ (path) @_is_code
+ (string) @injection.content))
+ (#eq? @_type "type")
+ (#match? @_is_shader "GDScript")
+ (#eq? @_is_code "script/source")
+ (#set! injection.language "gdscript")
+)
diff --git a/runtime/queries/godot-resource/textobjects.scm b/runtime/queries/godot-resource/textobjects.scm
new file mode 100644
index 00000000..aeb4e3eb
--- /dev/null
+++ b/runtime/queries/godot-resource/textobjects.scm
@@ -0,0 +1,23 @@
+(section
+ (identifier)
+ (_)
+ (property) @class.inside
+) @class.around
+
+(attribute
+ (identifier)
+ (_) @parameter.inside) @parameter.around
+
+(property
+ (path)
+ (_) @entry.inside) @entry.around
+
+(pair
+ (_) @entry.inside) @entry.around
+
+(array
+ (_) @entry.around)
+
+(comment) @comment.inside
+
+(comment)+ @comment.around