mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-16 10:20:11 -04:00
Fix: Improve Elixir highlighting performance (#1682)
This commit is contained in:
parent
2ac7858bd4
commit
d06ab28766
1 changed files with 127 additions and 153 deletions
|
|
@ -1,180 +1,154 @@
|
||||||
(identifier) @variable
|
(ERROR) @error
|
||||||
|
|
||||||
; _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
|
] @punctuation.bracket
|
||||||
|
|
||||||
(interpolation
|
[
|
||||||
"#{" @punctuation.special
|
","
|
||||||
"}" @punctuation.special) @none
|
"->"
|
||||||
|
"."
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
(sigil_start)
|
||||||
|
(sigil_end)
|
||||||
|
(heredoc_start)
|
||||||
|
(heredoc_end)
|
||||||
|
] @punctuation.special
|
||||||
|
|
||||||
|
(interpolation ["#{" "}"] @punctuation.special)
|
||||||
|
|
||||||
|
[
|
||||||
|
"after"
|
||||||
|
"and"
|
||||||
|
"catch"
|
||||||
|
"do"
|
||||||
|
"else"
|
||||||
|
"end"
|
||||||
|
"fn"
|
||||||
|
"in"
|
||||||
|
"not in"
|
||||||
|
"not"
|
||||||
|
"or"
|
||||||
|
"rescue"
|
||||||
|
"when"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
[
|
||||||
|
(comment)
|
||||||
|
(unused_identifier)
|
||||||
|
] @comment
|
||||||
|
|
||||||
[
|
[
|
||||||
(heredoc_content)
|
(heredoc_content)
|
||||||
(sigil_content)
|
(sigil_content)
|
||||||
(string_content)
|
(string)
|
||||||
(string_end)
|
|
||||||
(string_start)
|
|
||||||
] @string
|
] @string
|
||||||
|
|
||||||
|
; __MODULE__ and friends
|
||||||
|
(special_identifier) @constant.builtin
|
||||||
|
|
||||||
|
(map ["%{" "}"] @constructor)
|
||||||
|
|
||||||
|
(struct ["%" "{" "}"] @constructor)
|
||||||
|
|
||||||
|
(binary_op operator: _ @operator)
|
||||||
|
|
||||||
|
(unary_op operator: _ @operator)
|
||||||
|
|
||||||
|
(atom) @symbol
|
||||||
|
|
||||||
|
(keyword) @parameter
|
||||||
|
|
||||||
[
|
[
|
||||||
(heredoc_end)
|
(true)
|
||||||
(heredoc_start)
|
(false)
|
||||||
|
] @boolean
|
||||||
|
|
||||||
|
(nil) @constant.builtin
|
||||||
|
|
||||||
|
(sigil) @string.special
|
||||||
|
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
(module) @type
|
||||||
|
|
||||||
|
(function_identifier) @function
|
||||||
|
|
||||||
|
(integer) @number
|
||||||
|
|
||||||
|
(float) @float
|
||||||
|
|
||||||
|
[
|
||||||
|
(sigil_start)
|
||||||
(sigil_end)
|
(sigil_end)
|
||||||
(sigil_start)
|
|
||||||
] @string.special
|
] @string.special
|
||||||
|
|
||||||
(escape_sequence) @string.escape
|
; Module attributes as "attributes"
|
||||||
|
(unary_op operator: "@" @attribute [
|
||||||
|
(call function: (function_identifier) @attribute)
|
||||||
|
(identifier) @attribute
|
||||||
|
])
|
||||||
|
|
||||||
[
|
; Erlang modules (when they are the remote of a function call) are highlighted as Elixir modules
|
||||||
"after"
|
(dot_call remote: (atom) @type)
|
||||||
"do"
|
|
||||||
"end"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
[
|
(call (function_identifier) @keyword.function (#any-of? @keyword.function
|
||||||
"and"
|
"def"
|
||||||
"in"
|
"defdelegate"
|
||||||
"not"
|
"defexception"
|
||||||
"not in"
|
"defguard"
|
||||||
"or"
|
"defguardp"
|
||||||
] @keyword.operator
|
"defimpl"
|
||||||
|
"defmacro"
|
||||||
|
"defmacrop"
|
||||||
|
"defmodule"
|
||||||
|
"defoverridable"
|
||||||
|
"defp"
|
||||||
|
"defprotocol"
|
||||||
|
"defstruct"
|
||||||
|
) [(identifier) @function (_)]) ; 0-arity function def without parens
|
||||||
|
|
||||||
; Call to a local function
|
(call (function_identifier) @include (#any-of? @include
|
||||||
(call (function_identifier) @method)
|
"alias"
|
||||||
|
"import"
|
||||||
|
"require"
|
||||||
|
"use"
|
||||||
|
))
|
||||||
|
|
||||||
; Call to a remote (or external) function
|
(call (function_identifier) @conditional (#any-of? @conditional
|
||||||
(dot_call
|
"case"
|
||||||
remote: [(atom) (module)] @type
|
"cond"
|
||||||
function: (function_identifier) @method)
|
"else"
|
||||||
|
"if"
|
||||||
|
"unless"
|
||||||
|
"with"
|
||||||
|
"receive"
|
||||||
|
))
|
||||||
|
|
||||||
(dot_call
|
(call (function_identifier) @exception (#any-of? @exception
|
||||||
remote: (identifier) @variable
|
"raise"
|
||||||
function: (function_identifier) @method)
|
"reraise"
|
||||||
|
"throw"
|
||||||
|
"try"
|
||||||
|
))
|
||||||
|
|
||||||
"fn" @keyword.function
|
(call (function_identifier) @repeat (#any-of? @repeat
|
||||||
|
"for"
|
||||||
|
))
|
||||||
|
|
||||||
; def, defp, defguard, ... everything that starts with def
|
(call (function_identifier) @keyword.function (#any-of? @keyword.function
|
||||||
(call (function_identifier) @keyword.function
|
"describe"
|
||||||
(#lua-match? @keyword.function "^def%a*$"))
|
"setup"
|
||||||
|
"setup_all"
|
||||||
(call (function_identifier) @keyword.function
|
"test"
|
||||||
(#any-of? @keyword.function "describe" "doctest" "on_exit" "setup" "setup_all" "test"))
|
"using"
|
||||||
|
))
|
||||||
"else" @conditional
|
|
||||||
|
|
||||||
(call (function_identifier) @conditional
|
|
||||||
(#any-of? @conditional "case" "cond" "if" "unless" "with"))
|
|
||||||
|
|
||||||
(call (function_identifier) @repeat
|
|
||||||
(#eq? @repeat "for"))
|
|
||||||
|
|
||||||
(call (function_identifier) @include
|
|
||||||
(#any-of? @include "alias" "import" "require" "use"))
|
|
||||||
|
|
||||||
[
|
|
||||||
"catch"
|
|
||||||
"rescue"
|
|
||||||
] @exception
|
|
||||||
|
|
||||||
(call (function_identifier) @exception
|
|
||||||
(#any-of? @exception "raise" "try"))
|
|
||||||
|
|
||||||
; Regex sigil
|
|
||||||
(sigil
|
|
||||||
(sigil_start) @_sigil-type
|
|
||||||
[(sigil_content) (escape_sequence)] @string.regex
|
|
||||||
(sigil_end)
|
|
||||||
(#lua-match? @_sigil-type "^~r"))
|
|
||||||
|
|
||||||
"->" @operator
|
|
||||||
|
|
||||||
(unary_op
|
|
||||||
operator: _ @operator)
|
|
||||||
|
|
||||||
(binary_op
|
|
||||||
operator: _ @operator)
|
|
||||||
|
|
||||||
(unary_op
|
|
||||||
operator: "@" @attribute
|
|
||||||
[(call
|
|
||||||
function: (function_identifier) @attribute)
|
|
||||||
(identifier) @attribute])
|
|
||||||
|
|
||||||
(unary_op
|
|
||||||
operator: "@"
|
|
||||||
(call (function_identifier) @attribute
|
|
||||||
(heredoc
|
|
||||||
[(heredoc_start)
|
|
||||||
(heredoc_content)
|
|
||||||
(heredoc_end)] @string))
|
|
||||||
(#any-of? @attribute "doc" "moduledoc"))
|
|
||||||
|
|
||||||
(unary_op
|
|
||||||
operator: "@"
|
|
||||||
(call (function_identifier) @attribute
|
|
||||||
(binary_op
|
|
||||||
left: (identifier) @method))
|
|
||||||
(#eq? @attribute "spec"))
|
|
||||||
|
|
||||||
; Definition without arguments
|
|
||||||
(call (function_identifier) @keyword.function
|
|
||||||
(identifier) @function
|
|
||||||
(#lua-match? @keyword.function "^def%a*$"))
|
|
||||||
|
|
||||||
; Definition with (some) arguments and (optional) defaults
|
|
||||||
(call (function_identifier) @keyword.function
|
|
||||||
(call
|
|
||||||
function: (function_identifier) @function
|
|
||||||
(arguments))
|
|
||||||
(#lua-match? @keyword.function "^def%a*$"))
|
|
||||||
|
|
||||||
; Definition with (some) arguments and guard(s)
|
|
||||||
(call (function_identifier) @keyword.function
|
|
||||||
(binary_op
|
|
||||||
left:
|
|
||||||
(call
|
|
||||||
function: (function_identifier) @function
|
|
||||||
(arguments))
|
|
||||||
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
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue