mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 03:26:52 -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
|
||||
|
||||
; _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
|
||||
(ERROR) @error
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"<<"
|
||||
">>"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
"<<"
|
||||
">>"
|
||||
] @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)
|
||||
(sigil_content)
|
||||
(string_content)
|
||||
(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)
|
||||
(heredoc_start)
|
||||
(true)
|
||||
(false)
|
||||
] @boolean
|
||||
|
||||
(nil) @constant.builtin
|
||||
|
||||
(sigil) @string.special
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
(module) @type
|
||||
|
||||
(function_identifier) @function
|
||||
|
||||
(integer) @number
|
||||
|
||||
(float) @float
|
||||
|
||||
[
|
||||
(sigil_start)
|
||||
(sigil_end)
|
||||
(sigil_start)
|
||||
] @string.special
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
; Module attributes as "attributes"
|
||||
(unary_op operator: "@" @attribute [
|
||||
(call function: (function_identifier) @attribute)
|
||||
(identifier) @attribute
|
||||
])
|
||||
|
||||
[
|
||||
"after"
|
||||
"do"
|
||||
"end"
|
||||
] @keyword
|
||||
; Erlang modules (when they are the remote of a function call) are highlighted as Elixir modules
|
||||
(dot_call remote: (atom) @type)
|
||||
|
||||
[
|
||||
"and"
|
||||
"in"
|
||||
"not"
|
||||
"not in"
|
||||
"or"
|
||||
] @keyword.operator
|
||||
(call (function_identifier) @keyword.function (#any-of? @keyword.function
|
||||
"def"
|
||||
"defdelegate"
|
||||
"defexception"
|
||||
"defguard"
|
||||
"defguardp"
|
||||
"defimpl"
|
||||
"defmacro"
|
||||
"defmacrop"
|
||||
"defmodule"
|
||||
"defoverridable"
|
||||
"defp"
|
||||
"defprotocol"
|
||||
"defstruct"
|
||||
) [(identifier) @function (_)]) ; 0-arity function def without parens
|
||||
|
||||
; Call to a local function
|
||||
(call (function_identifier) @method)
|
||||
(call (function_identifier) @include (#any-of? @include
|
||||
"alias"
|
||||
"import"
|
||||
"require"
|
||||
"use"
|
||||
))
|
||||
|
||||
; Call to a remote (or external) function
|
||||
(dot_call
|
||||
remote: [(atom) (module)] @type
|
||||
function: (function_identifier) @method)
|
||||
(call (function_identifier) @conditional (#any-of? @conditional
|
||||
"case"
|
||||
"cond"
|
||||
"else"
|
||||
"if"
|
||||
"unless"
|
||||
"with"
|
||||
"receive"
|
||||
))
|
||||
|
||||
(dot_call
|
||||
remote: (identifier) @variable
|
||||
function: (function_identifier) @method)
|
||||
(call (function_identifier) @exception (#any-of? @exception
|
||||
"raise"
|
||||
"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
|
||||
(#lua-match? @keyword.function "^def%a*$"))
|
||||
|
||||
(call (function_identifier) @keyword.function
|
||||
(#any-of? @keyword.function "describe" "doctest" "on_exit" "setup" "setup_all" "test"))
|
||||
|
||||
"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
|
||||
(call (function_identifier) @keyword.function (#any-of? @keyword.function
|
||||
"describe"
|
||||
"setup"
|
||||
"setup_all"
|
||||
"test"
|
||||
"using"
|
||||
))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue