mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-10 07:20:06 -04:00
chore: query formatting
This commit is contained in:
parent
79975d6557
commit
57a8acf0c4
674 changed files with 18466 additions and 12648 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
(call (identifier) @function.call)
|
||||
(call (identifier) @keyword.import
|
||||
(#any-of? @keyword.import "preload" "load"))
|
||||
(default_parameter
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
;; Properties and Methods
|
||||
(call
|
||||
(identifier) @function.call)
|
||||
|
||||
(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
|
||||
"return" @keyword.return
|
||||
|
||||
[
|
||||
"await"
|
||||
] @keyword.coroutine
|
||||
"await" @keyword.coroutine
|
||||
|
||||
(call (identifier) @keyword.coroutine
|
||||
(#eq? @keyword.coroutine "yield"))
|
||||
(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"))
|
||||
|
||||
|
|
|
|||
|
|
@ -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) ) .)
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
(parameters (identifier) @local.definition.parameter)
|
||||
(default_parameter (identifier) @local.definition.parameter)
|
||||
(typed_parameter (identifier) @local.definition.parameter)
|
||||
(typed_default_parameter (identifier) @local.definition.parameter)
|
||||
(default_parameter
|
||||
(identifier) @local.definition.parameter)
|
||||
|
||||
;; Signals
|
||||
(typed_parameter
|
||||
(identifier) @local.definition.parameter)
|
||||
|
||||
(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"))
|
||||
|
||||
;; 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"))
|
||||
(body
|
||||
(function_definition
|
||||
(name) @local.definition.method)))
|
||||
(#set! "definition.method.scope" "parent"))
|
||||
|
||||
;; Enum
|
||||
; Enum
|
||||
((enum_definition
|
||||
(name) @local.definition.enum))
|
||||
|
||||
((enum_definition (name) @local.definition.enum))
|
||||
; Repeat
|
||||
(for_statement
|
||||
.
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
;; Repeat
|
||||
|
||||
(for_statement . (identifier) @local.definition.var)
|
||||
|
||||
;; Match Statement
|
||||
|
||||
(pattern_binding (identifier) @local.definition.var)
|
||||
|
||||
;; References
|
||||
; Match Statement
|
||||
(pattern_binding
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
; References
|
||||
(identifier) @local.reference
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue