mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-04 20:40:02 -04:00
feat!: drop modules, general refactor and cleanup
This commit is contained in:
parent
c13e28f894
commit
2c8f2f2fad
829 changed files with 4905 additions and 8010 deletions
25
runtime/queries/rust/folds.scm
Normal file
25
runtime/queries/rust/folds.scm
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
[(mod_item)
|
||||
(function_item)
|
||||
(struct_item)
|
||||
(trait_item)
|
||||
(enum_item)
|
||||
(impl_item)
|
||||
(type_item)
|
||||
(union_item)
|
||||
|
||||
(use_declaration)
|
||||
(let_declaration)
|
||||
|
||||
(loop_expression)
|
||||
(for_expression)
|
||||
(while_expression)
|
||||
(if_expression)
|
||||
(match_expression)
|
||||
(call_expression)
|
||||
(array_expression)
|
||||
|
||||
(macro_definition)
|
||||
(macro_invocation)
|
||||
|
||||
(attribute_item)
|
||||
] @fold
|
||||
384
runtime/queries/rust/highlights.scm
Normal file
384
runtime/queries/rust/highlights.scm
Normal file
|
|
@ -0,0 +1,384 @@
|
|||
; 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
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(const_item
|
||||
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) @field
|
||||
|
||||
(shorthand_field_initializer (identifier) @field)
|
||||
|
||||
(mod_item
|
||||
name: (identifier) @namespace)
|
||||
|
||||
(self) @variable.builtin
|
||||
|
||||
(loop_label ["'" (identifier)] @label)
|
||||
|
||||
; Function definitions
|
||||
|
||||
(function_item (identifier) @function)
|
||||
|
||||
(function_signature_item (identifier) @function)
|
||||
|
||||
(parameter (identifier) @parameter)
|
||||
|
||||
(closure_parameters (_) @parameter)
|
||||
|
||||
; Function calls
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
(identifier) @function.call .))
|
||||
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
|
||||
(generic_function
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(generic_function
|
||||
function: (scoped_identifier
|
||||
name: (identifier) @function.call))
|
||||
|
||||
(generic_function
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
|
||||
; Assume other uppercase names are enum constructors
|
||||
|
||||
((field_identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
(enum_variant
|
||||
name: (identifier) @constant)
|
||||
|
||||
; Assume that uppercase names in paths are types
|
||||
|
||||
(scoped_identifier
|
||||
path: (identifier) @namespace)
|
||||
|
||||
(scoped_identifier
|
||||
(scoped_identifier
|
||||
name: (identifier) @namespace))
|
||||
|
||||
(scoped_type_identifier
|
||||
path: (identifier) @namespace)
|
||||
|
||||
(scoped_type_identifier
|
||||
path: (identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(scoped_type_identifier
|
||||
(scoped_identifier
|
||||
name: (identifier) @namespace))
|
||||
|
||||
((scoped_identifier
|
||||
path: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((scoped_identifier
|
||||
name: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((scoped_identifier
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
|
||||
|
||||
((scoped_identifier
|
||||
path: (identifier) @type
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @type "^[A-Z]")
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((scoped_type_identifier
|
||||
path: (identifier) @type
|
||||
name: (type_identifier) @constant)
|
||||
(#lua-match? @type "^[A-Z]")
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
[
|
||||
(crate)
|
||||
(super)
|
||||
] @namespace
|
||||
|
||||
(scoped_use_list
|
||||
path: (identifier) @namespace)
|
||||
|
||||
(scoped_use_list
|
||||
path: (scoped_identifier
|
||||
(identifier) @namespace))
|
||||
|
||||
(use_list (scoped_identifier (identifier) @namespace . (_)))
|
||||
|
||||
(use_list (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)
|
||||
(#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
|
||||
(scoped_identifier
|
||||
name: (identifier) @constant)))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))
|
||||
|
||||
; Macro definitions
|
||||
|
||||
"$" @function.macro
|
||||
|
||||
(metavariable) @function.macro
|
||||
|
||||
(macro_definition "macro_rules!" @function.macro)
|
||||
|
||||
; Attribute macros
|
||||
|
||||
(attribute_item (attribute (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 .))
|
||||
|
||||
; Literals
|
||||
|
||||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @comment @spell
|
||||
|
||||
((line_comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^///[^/]"))
|
||||
|
||||
((line_comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^///$"))
|
||||
|
||||
((line_comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^//!"))
|
||||
|
||||
((block_comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
|
||||
|
||||
((block_comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^/[*][!]"))
|
||||
|
||||
(boolean_literal) @boolean
|
||||
|
||||
(integer_literal) @number
|
||||
|
||||
(float_literal) @float
|
||||
|
||||
[
|
||||
(raw_string_literal)
|
||||
(string_literal)
|
||||
] @string
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
(char_literal) @character
|
||||
|
||||
; Keywords
|
||||
|
||||
[
|
||||
"use"
|
||||
"mod"
|
||||
] @include
|
||||
|
||||
(use_as_clause "as" @include)
|
||||
|
||||
[
|
||||
"default"
|
||||
"enum"
|
||||
"impl"
|
||||
"let"
|
||||
"move"
|
||||
"pub"
|
||||
"struct"
|
||||
"trait"
|
||||
"type"
|
||||
"union"
|
||||
"unsafe"
|
||||
"where"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"async"
|
||||
"await"
|
||||
] @keyword.coroutine
|
||||
|
||||
[
|
||||
"ref"
|
||||
(mutable_specifier)
|
||||
] @type.qualifier
|
||||
|
||||
[
|
||||
"const"
|
||||
"static"
|
||||
"dyn"
|
||||
"extern"
|
||||
] @storageclass
|
||||
|
||||
(lifetime ["'" (identifier)] @storageclass.lifetime)
|
||||
|
||||
"fn" @keyword.function
|
||||
|
||||
[
|
||||
"return"
|
||||
"yield"
|
||||
] @keyword.return
|
||||
|
||||
(type_cast_expression "as" @keyword.operator)
|
||||
|
||||
(qualified_type "as" @keyword.operator)
|
||||
|
||||
(use_list (self) @namespace)
|
||||
|
||||
(scoped_use_list (self) @namespace)
|
||||
|
||||
(scoped_identifier [(crate) (super) (self)] @namespace)
|
||||
|
||||
(visibility_modifier [(crate) (super) (self)] @namespace)
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"match"
|
||||
] @conditional
|
||||
|
||||
[
|
||||
"break"
|
||||
"continue"
|
||||
"in"
|
||||
"loop"
|
||||
"while"
|
||||
] @repeat
|
||||
|
||||
"for" @keyword
|
||||
(for_expression "for" @repeat)
|
||||
|
||||
; Operators
|
||||
|
||||
[
|
||||
"!"
|
||||
"!="
|
||||
"%"
|
||||
"%="
|
||||
"&"
|
||||
"&&"
|
||||
"&="
|
||||
"*"
|
||||
"*="
|
||||
"+"
|
||||
"+="
|
||||
"-"
|
||||
"-="
|
||||
".."
|
||||
"..="
|
||||
"/"
|
||||
"/="
|
||||
"<"
|
||||
"<<"
|
||||
"<<="
|
||||
"<="
|
||||
"="
|
||||
"=="
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
">>="
|
||||
"?"
|
||||
"@"
|
||||
"^"
|
||||
"^="
|
||||
"|"
|
||||
"|="
|
||||
"||"
|
||||
] @operator
|
||||
|
||||
; Punctuation
|
||||
|
||||
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
||||
|
||||
(closure_parameters "|" @punctuation.bracket)
|
||||
|
||||
(type_arguments ["<" ">"] @punctuation.bracket)
|
||||
|
||||
(type_parameters ["<" ">"] @punctuation.bracket)
|
||||
|
||||
(bracketed_type ["<" ">"] @punctuation.bracket)
|
||||
|
||||
(for_lifetimes ["<" ">"] @punctuation.bracket)
|
||||
|
||||
["," "." ":" "::" ";" "->" "=>"] @punctuation.delimiter
|
||||
|
||||
(attribute_item "#" @punctuation.special)
|
||||
|
||||
(inner_attribute_item ["!" "#"] @punctuation.special)
|
||||
|
||||
(macro_invocation "!" @function.macro)
|
||||
|
||||
(empty_type "!" @type.builtin)
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @exception
|
||||
"!" @exception
|
||||
(#eq? @exception "panic"))
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @exception
|
||||
"!" @exception
|
||||
(#contains? @exception "assert"))
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @debug
|
||||
"!" @debug
|
||||
(#eq? @debug "dbg"))
|
||||
60
runtime/queries/rust/indents.scm
Normal file
60
runtime/queries/rust/indents.scm
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
[
|
||||
(mod_item)
|
||||
(struct_item)
|
||||
(enum_item)
|
||||
(impl_item)
|
||||
(for_expression)
|
||||
(struct_expression)
|
||||
(match_expression)
|
||||
(tuple_expression)
|
||||
(match_arm)
|
||||
(match_block)
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(arguments)
|
||||
(block)
|
||||
(where_clause)
|
||||
(use_list)
|
||||
(array_expression)
|
||||
(ordered_field_declaration_list)
|
||||
(field_declaration_list)
|
||||
(enum_variant_list)
|
||||
(parameters)
|
||||
(token_tree)
|
||||
(macro_definition)
|
||||
] @indent.begin
|
||||
(trait_item body: (_) @indent.begin)
|
||||
(string_literal (escape_sequence)) @indent.begin
|
||||
|
||||
(block "}" @indent.end)
|
||||
(enum_item
|
||||
body: (enum_variant_list "}" @indent.end))
|
||||
(impl_item
|
||||
body: (declaration_list "}" @indent.end))
|
||||
(match_expression
|
||||
body: (match_block "}" @indent.end))
|
||||
(mod_item
|
||||
body: (declaration_list "}" @indent.end))
|
||||
(struct_item
|
||||
body: (field_declaration_list "}" @indent.end))
|
||||
(trait_item
|
||||
body: (declaration_list "}" @indent.end))
|
||||
|
||||
(impl_item (where_clause) @indent.dedent)
|
||||
|
||||
[
|
||||
"where"
|
||||
")"
|
||||
"]"
|
||||
"}"
|
||||
] @indent.branch
|
||||
(impl_item (declaration_list) @indent.branch)
|
||||
|
||||
[
|
||||
(line_comment)
|
||||
(string_literal)
|
||||
] @indent.ignore
|
||||
|
||||
|
||||
(raw_string_literal) @indent.auto
|
||||
|
||||
43
runtime/queries/rust/injections.scm
Normal file
43
runtime/queries/rust/injections.scm
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(macro_invocation
|
||||
(token_tree) @injection.content (#set! injection.language "rust"))
|
||||
|
||||
(macro_definition
|
||||
(macro_rule
|
||||
left: (token_tree_pattern) @injection.content
|
||||
(#set! injection.language "rust")))
|
||||
|
||||
(macro_definition
|
||||
(macro_rule
|
||||
right: (token_tree) @injection.content
|
||||
(#set! injection.language "rust")))
|
||||
|
||||
([
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
((macro_invocation
|
||||
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"))
|
||||
|
||||
(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"))
|
||||
|
||||
((block_comment) @injection.content
|
||||
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
|
||||
(#set! injection.language "re2c"))
|
||||
103
runtime/queries/rust/locals.scm
Normal file
103
runtime/queries/rust/locals.scm
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
; Imports
|
||||
(extern_crate_declaration
|
||||
name: (identifier) @definition.import)
|
||||
|
||||
(use_declaration
|
||||
argument: (scoped_identifier
|
||||
name: (identifier) @definition.import))
|
||||
|
||||
(use_as_clause
|
||||
alias: (identifier) @definition.import)
|
||||
|
||||
(use_list
|
||||
(identifier) @definition.import) ; use std::process::{Child, Command, Stdio};
|
||||
|
||||
; Functions
|
||||
(function_item
|
||||
name: (identifier) @definition.function)
|
||||
|
||||
(function_item
|
||||
name: (identifier) @definition.method
|
||||
parameters: (parameters
|
||||
(self_parameter)))
|
||||
|
||||
; Variables
|
||||
(parameter
|
||||
pattern: (identifier) @definition.var)
|
||||
|
||||
(let_declaration
|
||||
pattern: (identifier) @definition.var)
|
||||
|
||||
(const_item
|
||||
name: (identifier) @definition.var)
|
||||
|
||||
(tuple_pattern
|
||||
(identifier) @definition.var)
|
||||
|
||||
(let_condition
|
||||
pattern: (_
|
||||
(identifier) @definition.var))
|
||||
|
||||
(tuple_struct_pattern
|
||||
(identifier) @definition.var)
|
||||
|
||||
(closure_parameters
|
||||
(identifier) @definition.var)
|
||||
|
||||
(self_parameter
|
||||
(self) @definition.var)
|
||||
|
||||
(for_expression
|
||||
pattern: (identifier) @definition.var)
|
||||
|
||||
; Types
|
||||
(struct_item
|
||||
name: (type_identifier) @definition.type)
|
||||
|
||||
(constrained_type_parameter
|
||||
left: (type_identifier) @definition.type) ; the P in remove_file<P: AsRef<Path>>(path: P)
|
||||
|
||||
(enum_item
|
||||
name: (type_identifier) @definition.type)
|
||||
|
||||
|
||||
; Fields
|
||||
(field_declaration
|
||||
name: (field_identifier) @definition.field)
|
||||
|
||||
(enum_variant
|
||||
name: (identifier) @definition.field)
|
||||
|
||||
; References
|
||||
(identifier) @reference
|
||||
((type_identifier) @reference
|
||||
(#set! reference.kind "type"))
|
||||
((field_identifier) @reference
|
||||
(#set! reference.kind "field"))
|
||||
|
||||
|
||||
; Macros
|
||||
(macro_definition
|
||||
name: (identifier) @definition.macro)
|
||||
|
||||
; Module
|
||||
(mod_item
|
||||
name: (identifier) @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)
|
||||
] @scope
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue