From b19551b11bc00ecd7386f6d9c420f373bfe3f377 Mon Sep 17 00:00:00 2001 From: Erasin Wang Date: Wed, 31 Jul 2024 04:52:47 +0800 Subject: [PATCH] Updated Godot support (#11235) - update gdscript highlights - add godot-resource textobjects --- book/src/generated/lang-support.md | 2 +- languages.toml | 6 ++-- runtime/queries/gdscript/highlights.scm | 3 ++ runtime/queries/gdscript/indents.scm | 1 + runtime/queries/gdscript/textobjects.scm | 9 +++++ runtime/queries/godot-resource/injections.scm | 35 ++++++++++++++++++- .../queries/godot-resource/textobjects.scm | 23 ++++++++++++ 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 runtime/queries/godot-resource/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 686dec5e2..9c88b7a20 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 0d268eecd..2bd57abb3 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 37aa3d62f..fee67dc9c 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 c969eb7cf..3d49aec35 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 47512bba7..3a2775fe2 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 7929d63cd..6e199f104 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 000000000..aeb4e3eb3 --- /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