aboutsummaryrefslogtreecommitdiffstats
path: root/queries/gdscript
diff options
context:
space:
mode:
authorPham Huy Hoang <hoangtun0810@gmail.com>2024-01-06 15:05:50 +0900
committerChristian Clason <c.clason@uni-graz.at>2024-01-19 16:58:37 +0100
commit57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9 (patch)
tree70bf645539882b88e6fa129cefd30986b89bbac3 /queries/gdscript
parentci: add query lint job (diff)
downloadnvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.gz
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.bz2
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.lz
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.xz
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.zst
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.zip
chore: query formatting
Diffstat (limited to 'queries/gdscript')
-rw-r--r--queries/gdscript/folds.scm8
-rw-r--r--queries/gdscript/highlights.scm165
-rw-r--r--queries/gdscript/indents.scm71
-rw-r--r--queries/gdscript/injections.scm4
-rw-r--r--queries/gdscript/locals.scm117
5 files changed, 223 insertions, 142 deletions
diff --git a/queries/gdscript/folds.scm b/queries/gdscript/folds.scm
index 946b0fea3..828ef807f 100644
--- a/queries/gdscript/folds.scm
+++ b/queries/gdscript/folds.scm
@@ -2,7 +2,6 @@
; Body fold will "join" the next adjacent fold into a SUPER fold.
; This is an issue with the grammar.
; (body)
-
(if_statement)
(elif_clause)
(else_clause)
@@ -16,10 +15,11 @@
(lambda)
(constructor_definition)
] @fold
-
; It's nice to be able to fold the if/elif/else clauses and the entire
; if_statement.
-(if_statement (body) @fold)
+(if_statement
+ (body) @fold)
; Fold strings that are probably doc strings.
-(expression_statement (string) @fold)
+(expression_statement
+ (string) @fold)
diff --git a/queries/gdscript/highlights.scm b/queries/gdscript/highlights.scm
index 21e0b8e0b..212bc67e3 100644
--- a/queries/gdscript/highlights.scm
+++ b/queries/gdscript/highlights.scm
@@ -1,23 +1,44 @@
-;; Basic
-
+; Basic
(identifier) @variable
+
(name) @variable
+
(type) @type
+
(comment) @comment @spell
+
(string_name) @string
+
(string) @string
+
(float) @number.float
+
(integer) @number
+
(null) @constant
+
(setter) @function
+
(getter) @function
-(set_body "set" @keyword.function)
-(get_body "get" @keyword.function)
+
+(set_body
+ "set" @keyword.function)
+
+(get_body
+ "get" @keyword.function)
+
(static_keyword) @type.qualifier
+
(tool_statement) @keyword
+
(breakpoint_statement) @keyword.debug
+
(inferred_type) @operator
-[(true) (false)] @boolean
+
+[
+ (true)
+ (false)
+] @boolean
[
(get_node)
@@ -31,68 +52,105 @@
"const" @type.qualifier
(name) @constant)
-(expression_statement (string) @comment @spell)
+(expression_statement
+ (string) @comment @spell)
-;; Identifier naming conventions
+; Identifier naming conventions
((identifier) @type
(#lua-match? @type "^[A-Z]"))
+
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
-;; Functions
+; Functions
(constructor_definition) @constructor
(function_definition
- (name) @function (parameters
+ (name) @function
+ (parameters
(identifier) @variable.parameter)*)
-(typed_parameter (identifier) @variable.parameter)
-(default_parameter (identifier) @variable.parameter)
+(typed_parameter
+ (identifier) @variable.parameter)
+
+(default_parameter
+ (identifier) @variable.parameter)
-(call (identifier) @function.call)
-(call (identifier) @keyword.import
- (#any-of? @keyword.import "preload" "load"))
+(call
+ (identifier) @function.call)
-;; Properties and Methods
+(call
+ (identifier) @keyword.import
+ (#any-of? @keyword.import "preload" "load"))
+; Properties and Methods
; We'll use @property since that's the term Godot uses.
; But, should (source (variable_statement (name))) be @property, too? Since a
; script file is a class in gdscript.
(class_definition
- (body (variable_statement (name) @property)))
+ (body
+ (variable_statement
+ (name) @property)))
; Same question but for methods?
(class_definition
- (body (function_definition (name) @function.method)))
+ (body
+ (function_definition
+ (name) @function.method)))
-(attribute_call (identifier) @function.method.call)
-(attribute (_) (identifier) @property)
+(attribute_call
+ (identifier) @function.method.call)
-;; Enums
+(attribute
+ (_)
+ (identifier) @property)
-(enumerator left: (identifier) @constant)
-
-;; Special Builtins
+; Enums
+(enumerator
+ left: (identifier) @constant)
+; Special Builtins
((identifier) @variable.builtin
(#any-of? @variable.builtin "self" "super"))
-(attribute_call (identifier) @keyword.operator
- (#eq? @keyword.operator "new"))
+(attribute_call
+ (identifier) @keyword.operator
+ (#eq? @keyword.operator "new"))
-;; Match Pattern
+; Match Pattern
+(underscore) @constant ; The "_" pattern.
-(underscore) @constant ; The "_" pattern.
(pattern_open_ending) @operator ; The ".." pattern.
-;; Alternations
-["(" ")" "[" "]" "{" "}"] @punctuation.bracket
+; Alternations
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
-["," "." ":"] @punctuation.delimiter
+[
+ ","
+ "."
+ ":"
+] @punctuation.delimiter
-["if" "elif" "else" "match"] @keyword.conditional
+[
+ "if"
+ "elif"
+ "else"
+ "match"
+] @keyword.conditional
-["for" "while" "break" "continue"] @keyword.repeat
+[
+ "for"
+ "while"
+ "break"
+ "continue"
+] @keyword.repeat
[
"~"
@@ -157,28 +215,24 @@
"func" @keyword.function
-[
- "return"
-] @keyword.return
-
-[
- "await"
-] @keyword.coroutine
+"return" @keyword.return
-(call (identifier) @keyword.coroutine
- (#eq? @keyword.coroutine "yield"))
+"await" @keyword.coroutine
+(call
+ (identifier) @keyword.coroutine
+ (#eq? @keyword.coroutine "yield"))
-;; Builtins
+; Builtins
; generated from
; - https://github.com/godotengine/godot/blob/491ded18983a4ae963ce9c29e8df5d5680873ccb/doc/classes/@GlobalScope.xml
; - https://github.com/godotengine/godot/blob/491ded18983a4ae963ce9c29e8df5d5680873ccb/modules/gdscript/doc_classes/@GDScript.xml
; some from:
; - https://github.com/godotengine/godot-vscode-plugin/blob/0636797c22bf1e23a41fd24d55cdb9be62e0c992/syntaxes/GDScript.tmLanguage.json
-
-;; Built-in Annotations
-
-((annotation "@" @attribute (identifier) @attribute)
+; Built-in Annotations
+((annotation
+ "@" @attribute
+ (identifier) @attribute)
; format-ignore
(#any-of? @attribute
; @GDScript
@@ -191,9 +245,11 @@
"export_placeholder" "export_range" "export_subgroup" "icon" "onready"
"rpc" "tool" "warning_ignore"))
-;; Builtin Types
-
-([(identifier) (type)] @type.builtin
+; Builtin Types
+([
+ (identifier)
+ (type)
+] @type.builtin
; format-ignore
(#any-of? @type.builtin
; from godot-vscode-plugin
@@ -220,9 +276,9 @@
"TranslationServer" "WorkerThreadPool" "XRServer"
))
-;; Builtin Funcs
-
-(call (identifier) @function.builtin
+; Builtin Funcs
+(call
+ (identifier) @function.builtin
; format-ignore
(#any-of? @function.builtin
; @GlobalScope
@@ -248,9 +304,7 @@
"Color8" "assert" "char" "convert" "dict_to_inst" "get_stack" "inst_to_dict"
"is_instance_of" "len" "print_debug" "print_stack" "range"
"type_exists"))
-
-;; Builtin Constants
-
+; Builtin Constants
((identifier) @constant.builtin
; format-ignore
(#any-of? @constant.builtin
@@ -341,4 +395,3 @@
"OP_EQUAL" "OP_NOT_EQUAL" "OP_LESS" "OP_LESS_EQUAL" "OP_GREATER" "OP_GREATER_EQUAL" "OP_ADD" "OP_SUBTRACT"
"OP_MULTIPLY" "OP_DIVIDE" "OP_NEGATE" "OP_POSITIVE" "OP_MODULE" "OP_POWER" "OP_SHIFT_LEFT" "OP_SHIFT_RIGHT"
"OP_BIT_AND" "OP_BIT_OR" "OP_BIT_XOR" "OP_BIT_NEGATE" "OP_AND" "OP_OR" "OP_XOR" "OP_NOT" "OP_IN" "OP_MAX"))
-
diff --git a/queries/gdscript/indents.scm b/queries/gdscript/indents.scm
index 4eb579b22..22d155e6f 100644
--- a/queries/gdscript/indents.scm
+++ b/queries/gdscript/indents.scm
@@ -1,7 +1,6 @@
[
(lambda)
(function_definition)
-
(for_statement)
(while_statement)
(if_statement)
@@ -20,12 +19,12 @@
] @indent.branch
[
- (string)
- (comment)
- (array)
- (dictionary)
- (parenthesized_expression)
- (ERROR)
+ (string)
+ (comment)
+ (array)
+ (dictionary)
+ (parenthesized_expression)
+ (ERROR)
] @indent.auto
[
@@ -36,43 +35,43 @@
] @indent.dedent
[
- (ERROR "[")
- (ERROR "(")
- (ERROR "{")
+ (ERROR
+ "[")
+ (ERROR
+ "(")
+ (ERROR
+ "{")
] @indent.begin
-;; This only works with expanded tabs.
+; This only works with expanded tabs.
; ((parameters) @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")"))
; ((arguments) @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")"))
-
-;; The following queries either do not agree with the current body parsing or are
-;; attempted workarounds. Specifically as the last statement of a body. Opening
-;; a new line in between statements works well.
-;;
-;; The overall experience is poor, so I've opted for @indent.auto.
-;;
-;; The gdscript parser will need to be patched to accommodate more interactive
-;; edits. As far as I can tell the parser greedily consumes whitespace
-;; as a zero-width token which causes trouble when inserting indents.
-
-;; This indents correctly with tabs.
+; The following queries either do not agree with the current body parsing or are
+; attempted workarounds. Specifically as the last statement of a body. Opening
+; a new line in between statements works well.
+;
+; The overall experience is poor, so I've opted for @indent.auto.
+;
+; The gdscript parser will need to be patched to accommodate more interactive
+; edits. As far as I can tell the parser greedily consumes whitespace
+; as a zero-width token which causes trouble when inserting indents.
+; This indents correctly with tabs.
; (arguments) @indent.begin
; (parameters) @indent.begin
; (array) @indent.begin
; (dictionary) @indent.begin
; (parenthesized_expression) @indent.begin
-
-;; Partial workaround for when the cursor is on the bracket character and a newline
-;; is created with <o>. Without this the newline is opened with extra
-;; indentation.
+; Partial workaround for when the cursor is on the bracket character and a newline
+; is created with <o>. Without this the newline is opened with extra
+; indentation.
; (body (_ (array "]" @indent.end) ) _)
-;; Problematic behaviors occur at the last statement of a body.
-;; with @dedent:
-;; - [ | ] i<CR> will dedent ] to 0.
-;; - [
-;; ]| o will open new line at correct indentation.
-;; with @auto:
-;; - [ | ] i<CR> same
-;; - [
-;; ]| o will open new line with extra indent.
+; Problematic behaviors occur at the last statement of a body.
+; with @dedent:
+; - [ | ] i<CR> will dedent ] to 0.
+; - [
+; ]| o will open new line at correct indentation.
+; with @auto:
+; - [ | ] i<CR> same
+; - [
+; ]| o will open new line with extra indent.
;(body (_ (array "]" @indent.auto) ) .)
diff --git a/queries/gdscript/injections.scm b/queries/gdscript/injections.scm
index 6adae45a2..2f0e58eb6 100644
--- a/queries/gdscript/injections.scm
+++ b/queries/gdscript/injections.scm
@@ -1,2 +1,2 @@
-((comment) @injection.content
- (#set! injection.language "comment"))
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/gdscript/locals.scm b/queries/gdscript/locals.scm
index ebcda4f7d..83a1b4433 100644
--- a/queries/gdscript/locals.scm
+++ b/queries/gdscript/locals.scm
@@ -1,5 +1,4 @@
-;; Scopes
-
+; Scopes
[
(if_statement)
(elif_clause)
@@ -16,77 +15,107 @@
(set_body)
] @local.scope
-;; Parameters
+; Parameters
+(parameters
+ (identifier) @local.definition.parameter)
+
+(default_parameter
+ (identifier) @local.definition.parameter)
-(parameters (identifier) @local.definition.parameter)
-(default_parameter (identifier) @local.definition.parameter)
-(typed_parameter (identifier) @local.definition.parameter)
-(typed_default_parameter (identifier) @local.definition.parameter)
+(typed_parameter
+ (identifier) @local.definition.parameter)
-;; Signals
+(typed_default_parameter
+ (identifier) @local.definition.parameter)
+; Signals
; Can gdscript 2 signals be considered fields?
-(signal_statement (name) @local.definition.field)
+(signal_statement
+ (name) @local.definition.field)
-;; Variable Definitions
+; Variable Definitions
+(const_statement
+ (name) @local.definition.constant)
-(const_statement (name) @local.definition.constant)
; onready and export variations are only properties.
-(variable_statement (name) @local.definition.var)
+(variable_statement
+ (name) @local.definition.var)
(setter) @local.reference
-(getter) @local.reference
-
-;; Function Definition
-((function_definition (name) @local.definition.function)
- (#set! "definition.function.scope" "parent"))
+(getter) @local.reference
-;; Lambda
+; Function Definition
+((function_definition
+ (name) @local.definition.function)
+ (#set! "definition.function.scope" "parent"))
+; Lambda
; lambda names are not accessible and are only for debugging.
-(lambda (name) @local.definition.function)
+(lambda
+ (name) @local.definition.function)
-;; Source
+; Source
+(class_name_statement
+ (name) @local.definition.type)
-(class_name_statement (name) @local.definition.type)
+(source
+ (variable_statement
+ (name) @local.definition.field))
-(source (variable_statement (name) @local.definition.field))
-(source (onready_variable_statement (name) @local.definition.field))
-(source (export_variable_statement (name) @local.definition.field))
+(source
+ (onready_variable_statement
+ (name) @local.definition.field))
-;; Class
+(source
+ (export_variable_statement
+ (name) @local.definition.field))
-((class_definition (name) @local.definition.type)
- (#set! "definition.type.scope" "parent"))
+; Class
+((class_definition
+ (name) @local.definition.type)
+ (#set! "definition.type.scope" "parent"))
(class_definition
- (body (variable_statement (name) @local.definition.field)))
+ (body
+ (variable_statement
+ (name) @local.definition.field)))
+
(class_definition
- (body (onready_variable_statement (name) @local.definition.field)))
+ (body
+ (onready_variable_statement
+ (name) @local.definition.field)))
+
(class_definition
- (body (export_variable_statement (name) @local.definition.field)))
+ (body
+ (export_variable_statement
+ (name) @local.definition.field)))
+
(class_definition
- (body (signal_statement (name) @local.definition.field)))
+ (body
+ (signal_statement
+ (name) @local.definition.field)))
; Although a script is also a class, let's only define functions in an inner class as
; methods.
((class_definition
- (body (function_definition (name) @local.definition.method)))
- (#set! "definition.method.scope" "parent"))
-
-;; Enum
-
-((enum_definition (name) @local.definition.enum))
-
-;; Repeat
-
-(for_statement . (identifier) @local.definition.var)
+ (body
+ (function_definition
+ (name) @local.definition.method)))
+ (#set! "definition.method.scope" "parent"))
-;; Match Statement
+; Enum
+((enum_definition
+ (name) @local.definition.enum))
-(pattern_binding (identifier) @local.definition.var)
+; Repeat
+(for_statement
+ .
+ (identifier) @local.definition.var)
-;; References
+; Match Statement
+(pattern_binding
+ (identifier) @local.definition.var)
+; References
(identifier) @local.reference