mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-15 18:00:07 -04:00
highlights(rust): organize keywords and literals
- sort keywords - highlight super as a namespace (same as crate) - highlight `break` and `continue` as `repeat` keywords - don't highlight `macro_rules!` as a keyword - place all literal queries together - place function definition queries alongside function call queries
This commit is contained in:
parent
81f75a54ff
commit
fbbcfa7b6c
1 changed files with 72 additions and 61 deletions
|
|
@ -23,6 +23,20 @@
|
||||||
(mod_item
|
(mod_item
|
||||||
name: (identifier) @namespace)
|
name: (identifier) @namespace)
|
||||||
|
|
||||||
|
(self) @variable.builtin
|
||||||
|
|
||||||
|
(lifetime ["'" (identifier)] @label)
|
||||||
|
(loop_label ["'" (identifier)] @label)
|
||||||
|
|
||||||
|
|
||||||
|
; Function definitions
|
||||||
|
|
||||||
|
(function_item (identifier) @function)
|
||||||
|
(function_signature_item (identifier) @function)
|
||||||
|
|
||||||
|
(parameter (identifier) @parameter)
|
||||||
|
(closure_parameters (_) @parameter)
|
||||||
|
|
||||||
; Function calls
|
; Function calls
|
||||||
(call_expression
|
(call_expression
|
||||||
function: (identifier) @function)
|
function: (identifier) @function)
|
||||||
|
|
@ -67,7 +81,11 @@
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(#lua-match? @type "^[A-Z]"))
|
(#lua-match? @type "^[A-Z]"))
|
||||||
|
|
||||||
(crate) @namespace
|
[
|
||||||
|
(crate)
|
||||||
|
(super)
|
||||||
|
] @namespace
|
||||||
|
|
||||||
(scoped_use_list
|
(scoped_use_list
|
||||||
path: (identifier) @namespace)
|
path: (identifier) @namespace)
|
||||||
(scoped_use_list
|
(scoped_use_list
|
||||||
|
|
@ -100,6 +118,7 @@
|
||||||
;; Macro definitions
|
;; Macro definitions
|
||||||
"$" @function.macro
|
"$" @function.macro
|
||||||
(metavariable) @function.macro
|
(metavariable) @function.macro
|
||||||
|
(macro_definition "macro_rules!" @function.macro)
|
||||||
|
|
||||||
;; Attribute macros
|
;; Attribute macros
|
||||||
(attribute_item (meta_item (identifier) @function.macro))
|
(attribute_item (meta_item (identifier) @function.macro))
|
||||||
|
|
@ -120,91 +139,83 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; Function definitions
|
;;; Literals
|
||||||
|
|
||||||
(function_item (identifier) @function)
|
|
||||||
(function_signature_item (identifier) @function)
|
|
||||||
|
|
||||||
[
|
[
|
||||||
(line_comment)
|
(line_comment)
|
||||||
(block_comment)
|
(block_comment)
|
||||||
] @comment
|
] @comment
|
||||||
|
|
||||||
(parameter (identifier) @parameter)
|
(boolean_literal) @boolean
|
||||||
(closure_parameters (_) @parameter)
|
(integer_literal) @number
|
||||||
|
(float_literal) @float
|
||||||
(lifetime ["'" (identifier)] @label)
|
|
||||||
(loop_label ["'" (identifier)] @label)
|
|
||||||
|
|
||||||
(self) @variable.builtin
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"use"
|
(char_literal)
|
||||||
"mod"
|
(raw_string_literal)
|
||||||
|
(string_literal)
|
||||||
|
] @string
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
|
|
||||||
|
;;; Keywords
|
||||||
|
|
||||||
|
[
|
||||||
|
"use"
|
||||||
|
"mod"
|
||||||
] @include
|
] @include
|
||||||
|
(use_as_clause "as" @include)
|
||||||
|
|
||||||
[
|
[
|
||||||
"break"
|
"async"
|
||||||
"const"
|
"await"
|
||||||
"default"
|
"const"
|
||||||
"dyn"
|
"default"
|
||||||
"enum"
|
"dyn"
|
||||||
"extern"
|
"enum"
|
||||||
"impl"
|
"extern"
|
||||||
"let"
|
"impl"
|
||||||
"macro_rules!"
|
"let"
|
||||||
"match"
|
"match"
|
||||||
"move"
|
"move"
|
||||||
"pub"
|
"pub"
|
||||||
"ref"
|
"ref"
|
||||||
"static"
|
"static"
|
||||||
"struct"
|
"struct"
|
||||||
"trait"
|
"trait"
|
||||||
"type"
|
"type"
|
||||||
"union"
|
"union"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"async"
|
"where"
|
||||||
"await"
|
(mutable_specifier)
|
||||||
"where"
|
|
||||||
(mutable_specifier)
|
|
||||||
(super)
|
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
|
"fn" @keyword.function
|
||||||
"return" @keyword.return
|
"return" @keyword.return
|
||||||
|
|
||||||
"fn" @keyword.function
|
(type_cast_expression "as" @keyword.operator)
|
||||||
|
|
||||||
(use_list (self) @keyword)
|
(use_list (self) @keyword)
|
||||||
(scoped_use_list (self) @keyword)
|
(scoped_use_list (self) @keyword)
|
||||||
(scoped_identifier (self) @keyword)
|
(scoped_identifier (self) @keyword)
|
||||||
|
|
||||||
[
|
[
|
||||||
"continue"
|
"else"
|
||||||
"else"
|
"if"
|
||||||
"if"
|
|
||||||
] @conditional
|
] @conditional
|
||||||
|
|
||||||
[
|
[
|
||||||
"for"
|
"break"
|
||||||
"in"
|
"continue"
|
||||||
"loop"
|
"for"
|
||||||
"while"
|
"in"
|
||||||
|
"loop"
|
||||||
|
"while"
|
||||||
] @repeat
|
] @repeat
|
||||||
|
|
||||||
[
|
|
||||||
(char_literal)
|
|
||||||
(string_literal)
|
|
||||||
(raw_string_literal)
|
|
||||||
] @string
|
|
||||||
|
|
||||||
(boolean_literal) @boolean
|
|
||||||
(integer_literal) @number
|
|
||||||
(float_literal) @float
|
|
||||||
|
|
||||||
(escape_sequence) @string.escape
|
;;; Operators & Punctuation
|
||||||
|
|
||||||
(type_cast_expression "as" @keyword.operator)
|
|
||||||
(use_as_clause "as" @include) ; path aliasing
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"!"
|
"!"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue