mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 03:40:04 -04:00
chore: query formatting
This commit is contained in:
parent
79975d6557
commit
57a8acf0c4
674 changed files with 18466 additions and 12648 deletions
|
|
@ -1,9 +1,7 @@
|
|||
; Forked from https://github.com/tree-sitter/tree-sitter-rust
|
||||
; Copyright (c) 2017 Maxim Sokolov
|
||||
; Licensed under the MIT license.
|
||||
|
||||
; Identifier conventions
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
((identifier) @type
|
||||
|
|
@ -13,77 +11,84 @@
|
|||
name: (identifier) @constant)
|
||||
|
||||
; Assume all-caps names are constants
|
||||
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
|
||||
|
||||
; Other identifiers
|
||||
|
||||
(type_identifier) @type
|
||||
|
||||
(primitive_type) @type.builtin
|
||||
|
||||
(field_identifier) @variable.member
|
||||
|
||||
(shorthand_field_initializer (identifier) @variable.member)
|
||||
(shorthand_field_initializer
|
||||
(identifier) @variable.member)
|
||||
|
||||
(mod_item
|
||||
name: (identifier) @module)
|
||||
|
||||
(self) @variable.builtin
|
||||
|
||||
(label ["'" (identifier)] @label)
|
||||
(label
|
||||
[
|
||||
"'"
|
||||
(identifier)
|
||||
] @label)
|
||||
|
||||
; Function definitions
|
||||
(function_item
|
||||
(identifier) @function)
|
||||
|
||||
(function_item (identifier) @function)
|
||||
(function_signature_item
|
||||
(identifier) @function)
|
||||
|
||||
(function_signature_item (identifier) @function)
|
||||
(parameter
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
(parameter (identifier) @variable.parameter)
|
||||
|
||||
(closure_parameters (_) @variable.parameter)
|
||||
(closure_parameters
|
||||
(_) @variable.parameter)
|
||||
|
||||
; Function calls
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
(identifier) @function.call .))
|
||||
function:
|
||||
(scoped_identifier
|
||||
(identifier) @function.call .))
|
||||
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
function:
|
||||
(field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
|
||||
(generic_function
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(generic_function
|
||||
function: (scoped_identifier
|
||||
name: (identifier) @function.call))
|
||||
function:
|
||||
(scoped_identifier
|
||||
name: (identifier) @function.call))
|
||||
|
||||
(generic_function
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
function:
|
||||
(field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
|
||||
; Assume other uppercase names are enum constructors
|
||||
|
||||
((field_identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
(enum_variant
|
||||
name: (identifier) @constant)
|
||||
|
||||
; Assume that uppercase names in paths are types
|
||||
|
||||
(scoped_identifier
|
||||
path: (identifier) @module)
|
||||
|
||||
(scoped_identifier
|
||||
(scoped_identifier
|
||||
name: (identifier) @module))
|
||||
(scoped_identifier
|
||||
name: (identifier) @module))
|
||||
|
||||
(scoped_type_identifier
|
||||
path: (identifier) @module)
|
||||
|
|
@ -93,20 +98,20 @@
|
|||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(scoped_type_identifier
|
||||
(scoped_identifier
|
||||
name: (identifier) @module))
|
||||
(scoped_identifier
|
||||
name: (identifier) @module))
|
||||
|
||||
((scoped_identifier
|
||||
path: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((scoped_identifier
|
||||
name: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
name: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((scoped_identifier
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
|
||||
|
||||
((scoped_identifier
|
||||
path: (identifier) @type
|
||||
|
|
@ -129,69 +134,85 @@
|
|||
path: (identifier) @module)
|
||||
|
||||
(scoped_use_list
|
||||
path: (scoped_identifier
|
||||
(identifier) @module))
|
||||
path:
|
||||
(scoped_identifier
|
||||
(identifier) @module))
|
||||
|
||||
(use_list (scoped_identifier (identifier) @module . (_)))
|
||||
(use_list
|
||||
(scoped_identifier
|
||||
(identifier) @module
|
||||
.
|
||||
(_)))
|
||||
|
||||
(use_list (identifier) @type (#lua-match? @type "^[A-Z]"))
|
||||
(use_list
|
||||
(identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(use_as_clause alias: (identifier) @type (#lua-match? @type "^[A-Z]"))
|
||||
(use_as_clause
|
||||
alias: (identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
; Correct enum constructors
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
"::"
|
||||
name: (identifier) @constant)
|
||||
function:
|
||||
(scoped_identifier
|
||||
"::"
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
; Assume uppercase names in a match arm are constants.
|
||||
((match_arm
|
||||
pattern:
|
||||
(match_pattern
|
||||
(identifier) @constant))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((match_arm
|
||||
pattern: (match_pattern (identifier) @constant))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((match_arm
|
||||
pattern: (match_pattern
|
||||
(scoped_identifier
|
||||
name: (identifier) @constant)))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
pattern:
|
||||
(match_pattern
|
||||
(scoped_identifier
|
||||
name: (identifier) @constant)))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))
|
||||
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))
|
||||
|
||||
; Macro definitions
|
||||
|
||||
"$" @function.macro
|
||||
|
||||
(metavariable) @function.macro
|
||||
|
||||
(macro_definition "macro_rules!" @function.macro)
|
||||
(macro_definition
|
||||
"macro_rules!" @function.macro)
|
||||
|
||||
; Attribute macros
|
||||
(attribute_item
|
||||
(attribute
|
||||
(identifier) @function.macro))
|
||||
|
||||
(attribute_item (attribute (identifier) @function.macro))
|
||||
(inner_attribute_item (attribute (identifier) @function.macro))
|
||||
(inner_attribute_item
|
||||
(attribute
|
||||
(identifier) @function.macro))
|
||||
|
||||
(attribute (scoped_identifier (identifier) @function.macro .))
|
||||
(attribute
|
||||
(scoped_identifier
|
||||
(identifier) @function.macro .))
|
||||
|
||||
; Derive macros (assume all arguments are types)
|
||||
; (attribute
|
||||
; (identifier) @_name
|
||||
; arguments: (attribute (attribute (identifier) @type))
|
||||
; (#eq? @_name "derive"))
|
||||
|
||||
; Function-like macros
|
||||
(macro_invocation
|
||||
macro: (identifier) @function.macro)
|
||||
|
||||
(macro_invocation
|
||||
macro: (scoped_identifier
|
||||
(identifier) @function.macro .))
|
||||
macro:
|
||||
(scoped_identifier
|
||||
(identifier) @function.macro .))
|
||||
|
||||
; Literals
|
||||
|
||||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
|
|
@ -228,13 +249,13 @@
|
|||
(char_literal) @character
|
||||
|
||||
; Keywords
|
||||
|
||||
[
|
||||
"use"
|
||||
"mod"
|
||||
] @keyword.import
|
||||
|
||||
(use_as_clause "as" @keyword.import)
|
||||
(use_as_clause
|
||||
"as" @keyword.import)
|
||||
|
||||
[
|
||||
"default"
|
||||
|
|
@ -258,7 +279,7 @@
|
|||
|
||||
[
|
||||
"ref"
|
||||
(mutable_specifier)
|
||||
(mutable_specifier)
|
||||
] @type.qualifier
|
||||
|
||||
[
|
||||
|
|
@ -268,7 +289,11 @@
|
|||
"extern"
|
||||
] @keyword.storage
|
||||
|
||||
(lifetime ["'" (identifier)] @keyword.storage.lifetime)
|
||||
(lifetime
|
||||
[
|
||||
"'"
|
||||
(identifier)
|
||||
] @keyword.storage.lifetime)
|
||||
|
||||
"fn" @keyword.function
|
||||
|
||||
|
|
@ -277,17 +302,31 @@
|
|||
"yield"
|
||||
] @keyword.return
|
||||
|
||||
(type_cast_expression "as" @keyword.operator)
|
||||
(type_cast_expression
|
||||
"as" @keyword.operator)
|
||||
|
||||
(qualified_type "as" @keyword.operator)
|
||||
(qualified_type
|
||||
"as" @keyword.operator)
|
||||
|
||||
(use_list (self) @module)
|
||||
(use_list
|
||||
(self) @module)
|
||||
|
||||
(scoped_use_list (self) @module)
|
||||
(scoped_use_list
|
||||
(self) @module)
|
||||
|
||||
(scoped_identifier [(crate) (super) (self)] @module)
|
||||
(scoped_identifier
|
||||
[
|
||||
(crate)
|
||||
(super)
|
||||
(self)
|
||||
] @module)
|
||||
|
||||
(visibility_modifier [(crate) (super) (self)] @module)
|
||||
(visibility_modifier
|
||||
[
|
||||
(crate)
|
||||
(super)
|
||||
(self)
|
||||
] @module)
|
||||
|
||||
[
|
||||
"if"
|
||||
|
|
@ -304,10 +343,11 @@
|
|||
] @keyword.repeat
|
||||
|
||||
"for" @keyword
|
||||
(for_expression "for" @keyword.repeat)
|
||||
|
||||
(for_expression
|
||||
"for" @keyword.repeat)
|
||||
|
||||
; Operators
|
||||
|
||||
[
|
||||
"!"
|
||||
"!="
|
||||
|
|
@ -346,28 +386,66 @@
|
|||
] @operator
|
||||
|
||||
; Punctuation
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
||||
(closure_parameters
|
||||
"|" @punctuation.bracket)
|
||||
|
||||
(closure_parameters "|" @punctuation.bracket)
|
||||
(type_arguments
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(type_arguments ["<" ">"] @punctuation.bracket)
|
||||
(type_parameters
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(type_parameters ["<" ">"] @punctuation.bracket)
|
||||
(bracketed_type
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(bracketed_type ["<" ">"] @punctuation.bracket)
|
||||
(for_lifetimes
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(for_lifetimes ["<" ">"] @punctuation.bracket)
|
||||
[
|
||||
","
|
||||
"."
|
||||
":"
|
||||
"::"
|
||||
";"
|
||||
"->"
|
||||
"=>"
|
||||
] @punctuation.delimiter
|
||||
|
||||
["," "." ":" "::" ";" "->" "=>"] @punctuation.delimiter
|
||||
(attribute_item
|
||||
"#" @punctuation.special)
|
||||
|
||||
(attribute_item "#" @punctuation.special)
|
||||
(inner_attribute_item
|
||||
[
|
||||
"!"
|
||||
"#"
|
||||
] @punctuation.special)
|
||||
|
||||
(inner_attribute_item ["!" "#"] @punctuation.special)
|
||||
(macro_invocation
|
||||
"!" @function.macro)
|
||||
|
||||
(macro_invocation "!" @function.macro)
|
||||
|
||||
(empty_type "!" @type.builtin)
|
||||
(empty_type
|
||||
"!" @type.builtin)
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @keyword.exception
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue