aboutsummaryrefslogtreecommitdiffstats
path: root/queries/rust
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/rust
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/rust')
-rw-r--r--queries/rust/folds.scm4
-rw-r--r--queries/rust/highlights.scm242
-rw-r--r--queries/rust/indents.scm50
-rw-r--r--queries/rust/injections.scm48
-rw-r--r--queries/rust/locals.scm81
5 files changed, 268 insertions, 157 deletions
diff --git a/queries/rust/folds.scm b/queries/rust/folds.scm
index 6372e6dfb..8d0b014fb 100644
--- a/queries/rust/folds.scm
+++ b/queries/rust/folds.scm
@@ -8,10 +8,8 @@
(impl_item)
(type_item)
(union_item)
-
(use_declaration)
(let_declaration)
-
(loop_expression)
(for_expression)
(while_expression)
@@ -19,9 +17,7 @@
(match_expression)
(call_expression)
(array_expression)
-
(macro_definition)
(macro_invocation)
-
(attribute_item)
] @fold
diff --git a/queries/rust/highlights.scm b/queries/rust/highlights.scm
index a262b6f08..2928271a3 100644
--- a/queries/rust/highlights.scm
+++ b/queries/rust/highlights.scm
@@ -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]"))
+ 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)
-; Operators
+(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
diff --git a/queries/rust/indents.scm b/queries/rust/indents.scm
index 0546efd25..6b9166518 100644
--- a/queries/rust/indents.scm
+++ b/queries/rust/indents.scm
@@ -23,24 +23,48 @@
(token_tree)
(macro_definition)
] @indent.begin
-(trait_item body: (_) @indent.begin)
-(string_literal (escape_sequence)) @indent.begin
-(block "}" @indent.end)
+(trait_item
+ body: (_) @indent.begin)
+
+(string_literal
+ (escape_sequence)) @indent.begin
+
+(block
+ "}" @indent.end)
+
(enum_item
- body: (enum_variant_list "}" @indent.end))
+ body:
+ (enum_variant_list
+ "}" @indent.end))
+
(impl_item
- body: (declaration_list "}" @indent.end))
+ body:
+ (declaration_list
+ "}" @indent.end))
+
(match_expression
- body: (match_block "}" @indent.end))
+ body:
+ (match_block
+ "}" @indent.end))
+
(mod_item
- body: (declaration_list "}" @indent.end))
+ body:
+ (declaration_list
+ "}" @indent.end))
+
(struct_item
- body: (field_declaration_list "}" @indent.end))
+ body:
+ (field_declaration_list
+ "}" @indent.end))
+
(trait_item
- body: (declaration_list "}" @indent.end))
+ body:
+ (declaration_list
+ "}" @indent.end))
-(impl_item (where_clause) @indent.dedent)
+(impl_item
+ (where_clause) @indent.dedent)
[
"where"
@@ -48,13 +72,13 @@
"]"
"}"
] @indent.branch
-(impl_item (declaration_list) @indent.branch)
+
+(impl_item
+ (declaration_list) @indent.branch)
[
(line_comment)
(string_literal)
] @indent.ignore
-
(raw_string_literal) @indent.auto
-
diff --git a/queries/rust/injections.scm b/queries/rust/injections.scm
index d3abc13a6..b245e3b64 100644
--- a/queries/rust/injections.scm
+++ b/queries/rust/injections.scm
@@ -1,9 +1,10 @@
(macro_invocation
- (token_tree) @injection.content (#set! injection.language "rust"))
+ (token_tree) @injection.content
+ (#set! injection.language "rust"))
(macro_definition
(macro_rule
- left: (token_tree_pattern) @injection.content
+ left: (token_tree_pattern) @injection.content
(#set! injection.language "rust")))
(macro_definition
@@ -15,28 +16,39 @@
(line_comment)
(block_comment)
] @injection.content
- (#set! injection.language "comment"))
+ (#set! injection.language "comment"))
((macro_invocation
- macro: ((identifier) @injection.language)
- (token_tree) @injection.content)
- (#eq? @injection.language "html"))
+ macro:
+ ((identifier) @injection.language)
+ (token_tree) @injection.content)
+ (#eq? @injection.language "html"))
(call_expression
- function: (scoped_identifier
- path: (identifier) @_regex (#eq? @_regex "Regex")
- name: (identifier) @_new (#eq? @_new "new"))
- arguments: (arguments
- (raw_string_literal) @injection.content)
- (#set! injection.language "regex"))
+ function:
+ (scoped_identifier
+ path: (identifier) @_regex
+ (#eq? @_regex "Regex")
+ name: (identifier) @_new
+ (#eq? @_new "new"))
+ arguments:
+ (arguments
+ (raw_string_literal) @injection.content)
+ (#set! injection.language "regex"))
(call_expression
- function: (scoped_identifier
- path: (scoped_identifier (identifier) @_regex (#eq? @_regex "Regex").)
- name: (identifier) @_new (#eq? @_new "new"))
- arguments: (arguments
- (raw_string_literal) @injection.content)
- (#set! injection.language "regex"))
+ function:
+ (scoped_identifier
+ path:
+ (scoped_identifier
+ (identifier) @_regex
+ (#eq? @_regex "Regex") .)
+ name: (identifier) @_new
+ (#eq? @_new "new"))
+ arguments:
+ (arguments
+ (raw_string_literal) @injection.content)
+ (#set! injection.language "regex"))
((block_comment) @injection.content
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
diff --git a/queries/rust/locals.scm b/queries/rust/locals.scm
index 24e2ffb0a..bba614536 100644
--- a/queries/rust/locals.scm
+++ b/queries/rust/locals.scm
@@ -1,42 +1,45 @@
; Imports
(extern_crate_declaration
- name: (identifier) @local.definition.import)
+ name: (identifier) @local.definition.import)
-(use_declaration
- argument: (scoped_identifier
- name: (identifier) @local.definition.import))
+(use_declaration
+ argument:
+ (scoped_identifier
+ name: (identifier) @local.definition.import))
-(use_as_clause
+(use_as_clause
alias: (identifier) @local.definition.import)
(use_list
- (identifier) @local.definition.import) ; use std::process::{Child, Command, Stdio};
+ (identifier) @local.definition.import) ; use std::process::{Child, Command, Stdio};
; Functions
-(function_item
- name: (identifier) @local.definition.function)
+(function_item
+ name: (identifier) @local.definition.function)
-(function_item
+(function_item
name: (identifier) @local.definition.method
- parameters: (parameters
- (self_parameter)))
+ parameters:
+ (parameters
+ (self_parameter)))
; Variables
-(parameter
- pattern: (identifier) @local.definition.var)
+(parameter
+ pattern: (identifier) @local.definition.var)
-(let_declaration
+(let_declaration
pattern: (identifier) @local.definition.var)
-(const_item
+(const_item
name: (identifier) @local.definition.var)
(tuple_pattern
- (identifier) @local.definition.var)
+ (identifier) @local.definition.var)
(let_condition
- pattern: (_
- (identifier) @local.definition.var))
+ pattern:
+ (_
+ (identifier) @local.definition.var))
(tuple_struct_pattern
(identifier) @local.definition.var)
@@ -47,57 +50,55 @@
(self_parameter
(self) @local.definition.var)
-(for_expression
+(for_expression
pattern: (identifier) @local.definition.var)
; Types
(struct_item
name: (type_identifier) @local.definition.type)
-(constrained_type_parameter
+(constrained_type_parameter
left: (type_identifier) @local.definition.type) ; the P in remove_file<P: AsRef<Path>>(path: P)
(enum_item
name: (type_identifier) @local.definition.type)
-
; Fields
(field_declaration
name: (field_identifier) @local.definition.field)
(enum_variant
- name: (identifier) @local.definition.field)
+ name: (identifier) @local.definition.field)
; References
(identifier) @local.reference
+
((type_identifier) @local.reference
- (#set! reference.kind "type"))
-((field_identifier) @local.reference
- (#set! reference.kind "field"))
+ (#set! reference.kind "type"))
+((field_identifier) @local.reference
+ (#set! reference.kind "field"))
; Macros
(macro_definition
name: (identifier) @local.definition.macro)
; Module
-(mod_item
+(mod_item
name: (identifier) @local.definition.namespace)
; Scopes
[
- (block)
- (function_item)
- (closure_expression)
- (while_expression)
- (for_expression)
- (loop_expression)
- (if_expression)
- (match_expression)
- (match_arm)
-
- (struct_item)
- (enum_item)
- (impl_item)
+ (block)
+ (function_item)
+ (closure_expression)
+ (while_expression)
+ (for_expression)
+ (loop_expression)
+ (if_expression)
+ (match_expression)
+ (match_arm)
+ (struct_item)
+ (enum_item)
+ (impl_item)
] @local.scope
-