mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 02:40:09 -04:00
Refactor highlights and locals queries
This commit is contained in:
parent
a04b0abf21
commit
a98e5c1f4f
2 changed files with 143 additions and 159 deletions
|
|
@ -1,9 +1,61 @@
|
||||||
(identifier) @variable
|
(identifier) @variable
|
||||||
|
|
||||||
|
; _unused variables
|
||||||
|
(unused_identifier) @comment
|
||||||
|
|
||||||
|
; __MODULE__ and friends
|
||||||
|
(special_identifier) @constant.builtin
|
||||||
|
|
||||||
|
(module) @type
|
||||||
|
|
||||||
|
[(atom) (keyword)] @symbol
|
||||||
|
|
||||||
|
(integer) @number
|
||||||
|
(float) @float
|
||||||
|
|
||||||
|
[(true) (false)] @boolean
|
||||||
|
|
||||||
|
(nil) @constant.builtin
|
||||||
|
|
||||||
|
(comment) @comment
|
||||||
|
|
||||||
|
[
|
||||||
|
","
|
||||||
|
"."
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"<<"
|
||||||
|
">>"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
(interpolation
|
(interpolation
|
||||||
"#{" @punctuation.special
|
"#{" @punctuation.special
|
||||||
"}" @punctuation.special) @none
|
"}" @punctuation.special) @none
|
||||||
|
|
||||||
|
[
|
||||||
|
(heredoc_content)
|
||||||
|
(sigil_content)
|
||||||
|
(string_content)
|
||||||
|
(string_end)
|
||||||
|
(string_start)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
[
|
||||||
|
(heredoc_end)
|
||||||
|
(heredoc_start)
|
||||||
|
(sigil_end)
|
||||||
|
(sigil_start)
|
||||||
|
] @string.special
|
||||||
|
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
[
|
[
|
||||||
"after"
|
"after"
|
||||||
"do"
|
"do"
|
||||||
|
|
@ -18,33 +70,17 @@
|
||||||
"or"
|
"or"
|
||||||
] @keyword.operator
|
] @keyword.operator
|
||||||
|
|
||||||
|
; Call to a local function
|
||||||
(call (function_identifier) @method)
|
(call (function_identifier) @method)
|
||||||
|
|
||||||
(call (function_identifier) @keyword
|
; Call to a remote (or external) function
|
||||||
(#any-of? @keyword
|
(dot_call
|
||||||
"quote"
|
remote: [(atom) (module)] @type
|
||||||
"receive"
|
function: (function_identifier) @method)
|
||||||
"self"
|
|
||||||
"super"
|
|
||||||
"unquote"
|
|
||||||
"unquote_splicing"
|
|
||||||
"with"
|
|
||||||
"assert"
|
|
||||||
"assert_in_delta"
|
|
||||||
"assert_raise"
|
|
||||||
"assert_receive"
|
|
||||||
"assert_received"
|
|
||||||
"catch_error"
|
|
||||||
"catch_exit"
|
|
||||||
"catch_throw"
|
|
||||||
"flunk"
|
|
||||||
"refute"
|
|
||||||
"refute_in_delta"
|
|
||||||
"refute_receive"
|
|
||||||
"refute_received"))
|
|
||||||
|
|
||||||
"fn" @keyword.function
|
"fn" @keyword.function
|
||||||
|
|
||||||
|
; def, defp, defguard, ... everything that starts with def
|
||||||
(call (function_identifier) @keyword.function
|
(call (function_identifier) @keyword.function
|
||||||
(#lua-match? @keyword.function "^def%a*$"))
|
(#lua-match? @keyword.function "^def%a*$"))
|
||||||
|
|
||||||
|
|
@ -70,41 +106,13 @@
|
||||||
(call (function_identifier) @exception
|
(call (function_identifier) @exception
|
||||||
(#any-of? @exception "raise" "try"))
|
(#any-of? @exception "raise" "try"))
|
||||||
|
|
||||||
[
|
; Regex sigil
|
||||||
(heredoc_content)
|
|
||||||
(sigil_content)
|
|
||||||
(string_content)
|
|
||||||
(string_end)
|
|
||||||
(string_start)
|
|
||||||
] @string
|
|
||||||
|
|
||||||
[
|
|
||||||
(heredoc_end)
|
|
||||||
(heredoc_start)
|
|
||||||
(sigil_end)
|
|
||||||
(sigil_start)
|
|
||||||
] @string.special
|
|
||||||
|
|
||||||
(sigil
|
(sigil
|
||||||
(sigil_start) @_sigil-type
|
(sigil_start) @_sigil-type
|
||||||
[(sigil_content) (escape_sequence)] @string.regex
|
[(sigil_content) (escape_sequence)] @string.regex
|
||||||
(sigil_end)
|
(sigil_end)
|
||||||
(#lua-match? @_sigil-type "^~r"))
|
(#lua-match? @_sigil-type "^~r"))
|
||||||
|
|
||||||
(module) @type
|
|
||||||
|
|
||||||
[(atom) (keyword)] @symbol
|
|
||||||
|
|
||||||
(escape_sequence) @string.escape
|
|
||||||
(integer) @number
|
|
||||||
(float) @float
|
|
||||||
|
|
||||||
[(true) (false)] @boolean
|
|
||||||
|
|
||||||
(nil) @constant.builtin
|
|
||||||
|
|
||||||
(comment) @comment
|
|
||||||
|
|
||||||
"->" @operator
|
"->" @operator
|
||||||
|
|
||||||
(unary_op
|
(unary_op
|
||||||
|
|
@ -135,56 +143,47 @@
|
||||||
left: (identifier) @method))
|
left: (identifier) @method))
|
||||||
(#eq? @attribute "spec"))
|
(#eq? @attribute "spec"))
|
||||||
|
|
||||||
[
|
; Definition without arguments
|
||||||
","
|
|
||||||
"."
|
|
||||||
] @punctuation.delimiter
|
|
||||||
|
|
||||||
[
|
|
||||||
"("
|
|
||||||
")"
|
|
||||||
"["
|
|
||||||
"]"
|
|
||||||
"{"
|
|
||||||
"}"
|
|
||||||
"<<"
|
|
||||||
">>"
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
(dot_call
|
|
||||||
remote: [(atom) (module)] @type
|
|
||||||
function: (function_identifier) @method)
|
|
||||||
|
|
||||||
(call (function_identifier) @keyword.function
|
(call (function_identifier) @keyword.function
|
||||||
[(call
|
(identifier) @function
|
||||||
(function_identifier) @function)
|
(#lua-match? @keyword.function "^def%a*$"))
|
||||||
(call
|
|
||||||
function: (function_identifier) @function
|
|
||||||
(arguments
|
|
||||||
[(identifier) @parameter
|
|
||||||
(binary_op
|
|
||||||
left: (identifier) @parameter)]))
|
|
||||||
(identifier) @function
|
|
||||||
(binary_op
|
|
||||||
left:
|
|
||||||
[(call
|
|
||||||
function: (function_identifier) @function
|
|
||||||
(arguments
|
|
||||||
[(identifier) @parameter
|
|
||||||
(binary_op
|
|
||||||
left: (identifier) @parameter)]))
|
|
||||||
(identifier) @function]
|
|
||||||
operator: "when")
|
|
||||||
(binary_op
|
|
||||||
left: (identifier)
|
|
||||||
operator: _ @function
|
|
||||||
right: (identifier))]
|
|
||||||
(#lua-match? @keyword.function "^def%a*$"))
|
|
||||||
|
|
||||||
((identifier) @comment
|
; Definition with (some) arguments and (optional) defaults
|
||||||
(#lua-match? @comment "^_[%a%d_]*$"))
|
(call (function_identifier) @keyword.function
|
||||||
|
(call
|
||||||
|
function: (function_identifier) @function
|
||||||
|
(arguments
|
||||||
|
[(identifier) @parameter
|
||||||
|
(tuple (identifier) @parameter)
|
||||||
|
(list (identifier) @parameter)
|
||||||
|
(_
|
||||||
|
(keyword_list (identifier) @parameter))
|
||||||
|
(binary_op
|
||||||
|
left: (identifier) @parameter
|
||||||
|
operator: "\\\\")]))
|
||||||
|
(#lua-match? @keyword.function "^def%a*$"))
|
||||||
|
|
||||||
((identifier) @constant.builtin
|
; Definition with (some) arguments and guard(s)
|
||||||
(#lua-match? @constant.builtin "^__[%a%d_]+__$"))
|
(call (function_identifier) @keyword.function
|
||||||
|
(binary_op
|
||||||
|
left:
|
||||||
|
(call
|
||||||
|
function: (function_identifier) @function
|
||||||
|
(arguments
|
||||||
|
[(identifier) @parameter
|
||||||
|
(tuple (identifier) @parameter)
|
||||||
|
(list (identifier) @parameter)
|
||||||
|
(_
|
||||||
|
(keyword_list (identifier) @parameter))]))
|
||||||
|
operator: "when")
|
||||||
|
(#lua-match? @keyword.function "^def%a*$"))
|
||||||
|
|
||||||
|
; Definition of custom binary operator(s)
|
||||||
|
(call (function_identifier) @keyword.function
|
||||||
|
(binary_op
|
||||||
|
left: (identifier) @parameter
|
||||||
|
operator: _ @function
|
||||||
|
right: (identifier) @parameter)
|
||||||
|
(#any-of? @keyword.function "def" "defp"))
|
||||||
|
|
||||||
(ERROR) @error
|
(ERROR) @error
|
||||||
|
|
|
||||||
|
|
@ -13,83 +13,68 @@
|
||||||
(module) @definition.type
|
(module) @definition.type
|
||||||
(#eq? @_call-name "defmodule"))
|
(#eq? @_call-name "defmodule"))
|
||||||
|
|
||||||
(call
|
; Function definition without arguments
|
||||||
function: (function_identifier) @_call-name
|
(call (function_identifier) @_call-name
|
||||||
(call
|
(identifier) @definition.function
|
||||||
function: (function_identifier) @definition.function)
|
(#any-of? @_call-name "def" "defp" "defguard" "defguardp"))
|
||||||
(#any-of? @_call-name "def" "defp"))
|
|
||||||
|
|
||||||
(call
|
; Function definition with arguments
|
||||||
function: (function_identifier) @_call-name
|
(call (function_identifier) @_call-name
|
||||||
(call
|
(call
|
||||||
function: (function_identifier) @definition.function
|
function: (function_identifier) @definition.function
|
||||||
(arguments
|
(arguments
|
||||||
[(identifier) @definition.parameter
|
[(identifier) @definition.parameter
|
||||||
(tuple
|
(tuple (identifier) @definition.parameter)
|
||||||
(identifier) @definition.parameter)
|
(list (identifier) @definition.parameter)
|
||||||
(list
|
(_
|
||||||
(identifier) @definition.parameter)
|
(keyword_list (identifier) @definition.parameter))
|
||||||
(map
|
|
||||||
(keyword_list
|
|
||||||
(identifier) @definition.parameter))
|
|
||||||
(struct
|
|
||||||
(keyword_list
|
|
||||||
(identifier) @definition.parameter))
|
|
||||||
(binary_op
|
(binary_op
|
||||||
left: (identifier) @definition.parameter
|
left: (identifier) @definition.parameter
|
||||||
operator: "\\\\")]
|
operator: "\\\\")]))
|
||||||
(#lua-match? @definition.parameter "^[^_]")))
|
|
||||||
(#any-of? @_call-name "def" "defp"))
|
(#any-of? @_call-name "def" "defp"))
|
||||||
|
|
||||||
(call
|
; Function definition with (some) arguments and guard(s)
|
||||||
function: (function_identifier) @_call-name
|
(call (function_identifier) @_call-name
|
||||||
(binary_op
|
(binary_op
|
||||||
left: (call
|
left:
|
||||||
function: (function_identifier) @definition.function
|
(call
|
||||||
(arguments
|
function: (function_identifier) @definition.function
|
||||||
[(identifier) @definition.parameter
|
(arguments
|
||||||
(tuple
|
[(identifier) @definition.parameter
|
||||||
(identifier) @definition.parameter)
|
(tuple (identifier) @definition.parameter)
|
||||||
(list
|
(list (identifier) @definition.parameter)
|
||||||
(identifier) @definition.parameter)
|
(_
|
||||||
(map
|
(keyword_list (identifier) @definition.parameter))]))
|
||||||
(keyword_list
|
|
||||||
(identifier) @definition.parameter))
|
|
||||||
(struct
|
|
||||||
(keyword_list
|
|
||||||
(identifier) @definition.parameter))]
|
|
||||||
(#lua-match? @definition.parameter "^[^_]")))
|
|
||||||
operator: "when")
|
operator: "when")
|
||||||
(#any-of? @_call-name "def" "defp"))
|
(#any-of? @_call-name "def" "defp" "defguard" "defguardp"))
|
||||||
|
|
||||||
|
; Variable assignment and simple pattern matching
|
||||||
(binary_op
|
(binary_op
|
||||||
left:
|
left:
|
||||||
[(identifier) @definition.var
|
[(identifier) @definition.var
|
||||||
(tuple
|
(tuple (identifier) @definition.var)
|
||||||
(identifier) @definition.var)
|
(list (identifier) @definition.var)
|
||||||
(list
|
(_
|
||||||
(identifier) @definition.var)
|
(keyword_list (identifier) @definition.var))]
|
||||||
(map
|
operator: "=")
|
||||||
(keyword_list
|
|
||||||
(identifier) @definition.var))
|
|
||||||
(struct
|
|
||||||
(keyword_list
|
|
||||||
(identifier) @definition.var))]
|
|
||||||
operator: "="
|
|
||||||
(#lua-match? @definition.var "^[^_]"))
|
|
||||||
|
|
||||||
|
; Simple stab expression (ex. case pattern matching) without guard(s)
|
||||||
(stab_expression
|
(stab_expression
|
||||||
left:
|
left:
|
||||||
(bare_arguments
|
(bare_arguments
|
||||||
[(identifier) @definition.var
|
[(identifier) @definition.var
|
||||||
(tuple
|
(tuple (identifier) @definition.var)
|
||||||
(identifier) @definition.var)
|
(list (identifier) @definition.var)
|
||||||
(list
|
(_
|
||||||
(identifier) @definition.var)
|
(keyword_list (identifier) @definition.var))]))
|
||||||
(map
|
|
||||||
(keyword_list
|
; Simple stab expression (ex. case pattern matching) with guard(s)
|
||||||
(identifier) @definition.var))
|
(stab_expression
|
||||||
(struct
|
left:
|
||||||
(keyword_list
|
(bare_arguments
|
||||||
(identifier) @definition.var))])
|
(binary_op
|
||||||
(#lua-match? @definition.var "^[^_]"))
|
left: [(identifier) @definition.var
|
||||||
|
(tuple (identifier) @definition.var)
|
||||||
|
(list (identifier) @definition.var)
|
||||||
|
(_
|
||||||
|
(keyword_list (identifier) @definition.var))])))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue