From c71b4c5579fdc753e62300f5ee6ca5e747a98e13 Mon Sep 17 00:00:00 2001
From: Erasin <erasinoo@gmail.com>
Date: Mon, 13 Feb 2023 04:03:02 +0800
Subject: [PATCH] Update grammar for godot (#5944)

* update grammar for gdscript.
* add comment injections for gdscript.
* add indent for gdscript
* add file-type support for godot-resource
---
 book/src/generated/lang-support.md            |  2 +-
 languages.toml                                |  4 +--
 runtime/queries/gdscript/indents.scm          | 35 +++++++++++++++++++
 runtime/queries/gdscript/injections.scm       |  2 ++
 runtime/queries/godot-resource/highlights.scm |  3 +-
 runtime/queries/godot-resource/injections.scm |  2 ++
 6 files changed, 44 insertions(+), 4 deletions(-)
 create mode 100644 runtime/queries/gdscript/indents.scm
 create mode 100644 runtime/queries/gdscript/injections.scm
 create mode 100644 runtime/queries/godot-resource/injections.scm

diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index e6b68c8c..c31ddd3d 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -38,7 +38,7 @@
 | esdl | ✓ |  |  |  |
 | fish | ✓ | ✓ | ✓ |  |
 | fortran | ✓ |  | ✓ | `fortls` |
-| gdscript | ✓ | ✓ |  |  |
+| gdscript | ✓ | ✓ | ✓ |  |
 | git-attributes | ✓ |  |  |  |
 | git-commit | ✓ |  |  |  |
 | git-config | ✓ |  |  |  |
diff --git a/languages.toml b/languages.toml
index 311ef689..eaf73b41 100644
--- a/languages.toml
+++ b/languages.toml
@@ -1449,13 +1449,13 @@ indent = { tab-width = 4, unit = "\t" }
 
 [[grammar]]
 name = "gdscript"
-source = { git = "https://github.com/PrestonKnopp/tree-sitter-gdscript", rev = "2a6abdaa47fcb91397e09a97c7433fd995ea46c6" }
+source = { git = "https://github.com/PrestonKnopp/tree-sitter-gdscript", rev = "a56a6fcec3fb63ec3324bf9373aae7298861eb30" }
 
 [[language]]
 name = "godot-resource"
 scope = "source.tscn"
 injection-regex = "godot"
-file-types = ["tscn","tres"]
+file-types = ["tscn", "tres", "godot", "gdextension"]
 shebangs = []
 roots = ["project.godot"]
 auto-format = false
diff --git a/runtime/queries/gdscript/indents.scm b/runtime/queries/gdscript/indents.scm
new file mode 100644
index 00000000..1ab41a44
--- /dev/null
+++ b/runtime/queries/gdscript/indents.scm
@@ -0,0 +1,35 @@
+[
+  (if_statement)
+  (for_statement)
+  (while_statement)
+  (match_statement)
+  (pattern_section)
+
+  (function_definition)
+  (constructor_definition)
+  (class_definition)
+  (enum_definition)
+
+  (dictionary (_))
+  (array (_))
+] @indent
+
+[
+  (if_statement)
+  (for_statement)
+  (while_statement)
+  (match_statement)
+  (pattern_section)
+
+  (function_definition)
+  (class_definition)
+] @extend
+
+
+[
+  (return_statement)
+  (break_statement)
+  (continue_statement)
+  (pass_statement)
+] @extend.prevent-once
+
diff --git a/runtime/queries/gdscript/injections.scm b/runtime/queries/gdscript/injections.scm
new file mode 100644
index 00000000..321c90ad
--- /dev/null
+++ b/runtime/queries/gdscript/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/runtime/queries/godot-resource/highlights.scm b/runtime/queries/godot-resource/highlights.scm
index 18dae41f..d8a69f65 100644
--- a/runtime/queries/godot-resource/highlights.scm
+++ b/runtime/queries/godot-resource/highlights.scm
@@ -25,4 +25,5 @@
 
 "=" @operator
 
-(ERROR) @error
\ No newline at end of file
+(ERROR) @error
+(comment) @comment
diff --git a/runtime/queries/godot-resource/injections.scm b/runtime/queries/godot-resource/injections.scm
new file mode 100644
index 00000000..321c90ad
--- /dev/null
+++ b/runtime/queries/godot-resource/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))