summaryrefslogtreecommitdiffstats
path: root/queries/elixir
diff options
context:
space:
mode:
authorConnor Lay (Clay) <connorlay@users.noreply.github.com>2021-08-13 10:09:16 -0700
committerGitHub <noreply@github.com>2021-08-13 12:09:16 -0500
commitd06ab287662eef5945daca71ed77942a095fa5a1 (patch)
treef250207fcbb394650ae0f1fac59110877ab8a653 /queries/elixir
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.tar
nvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.tar.gz
nvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.tar.bz2
nvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.tar.lz
nvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.tar.xz
nvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.tar.zst
nvim-treesitter-d06ab287662eef5945daca71ed77942a095fa5a1.zip
Fix: Improve Elixir highlighting performance (#1682)
Diffstat (limited to 'queries/elixir')
-rw-r--r--queries/elixir/highlights.scm240
1 files changed, 107 insertions, 133 deletions
diff --git a/queries/elixir/highlights.scm b/queries/elixir/highlights.scm
index 51c57494d..413ae6cc8 100644
--- a/queries/elixir/highlights.scm
+++ b/queries/elixir/highlights.scm
@@ -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
-
[
- (heredoc_content)
- (sigil_content)
- (string_content)
- (string_end)
- (string_start)
-] @string
+ ","
+ "->"
+ "."
+] @punctuation.delimiter
[
- (heredoc_end)
- (heredoc_start)
- (sigil_end)
(sigil_start)
-] @string.special
+ (sigil_end)
+ (heredoc_start)
+ (heredoc_end)
+] @punctuation.special
-(escape_sequence) @string.escape
+(interpolation ["#{" "}"] @punctuation.special)
[
"after"
+ "and"
+ "catch"
"do"
+ "else"
"end"
-] @keyword
-
-[
- "and"
+ "fn"
"in"
- "not"
"not in"
+ "not"
"or"
-] @keyword.operator
-
-; Call to a local function
-(call (function_identifier) @method)
+ "rescue"
+ "when"
+] @keyword
-; Call to a remote (or external) function
-(dot_call
- remote: [(atom) (module)] @type
- function: (function_identifier) @method)
+[
+ (comment)
+ (unused_identifier)
+] @comment
-(dot_call
- remote: (identifier) @variable
- function: (function_identifier) @method)
+[
+ (heredoc_content)
+ (sigil_content)
+ (string)
+] @string
-"fn" @keyword.function
+; __MODULE__ and friends
+(special_identifier) @constant.builtin
-; def, defp, defguard, ... everything that starts with def
-(call (function_identifier) @keyword.function
- (#lua-match? @keyword.function "^def%a*$"))
+(map ["%{" "}"] @constructor)
-(call (function_identifier) @keyword.function
- (#any-of? @keyword.function "describe" "doctest" "on_exit" "setup" "setup_all" "test"))
+(struct ["%" "{" "}"] @constructor)
-"else" @conditional
+(binary_op operator: _ @operator)
-(call (function_identifier) @conditional
- (#any-of? @conditional "case" "cond" "if" "unless" "with"))
+(unary_op operator: _ @operator)
-(call (function_identifier) @repeat
- (#eq? @repeat "for"))
+(atom) @symbol
-(call (function_identifier) @include
- (#any-of? @include "alias" "import" "require" "use"))
+(keyword) @parameter
[
- "catch"
- "rescue"
-] @exception
+ (true)
+ (false)
+] @boolean
-(call (function_identifier) @exception
- (#any-of? @exception "raise" "try"))
+(nil) @constant.builtin
-; Regex sigil
-(sigil
- (sigil_start) @_sigil-type
- [(sigil_content) (escape_sequence)] @string.regex
- (sigil_end)
- (#lua-match? @_sigil-type "^~r"))
+(sigil) @string.special
-"->" @operator
+(identifier) @variable
-(unary_op
- operator: _ @operator)
+(module) @type
-(binary_op
- operator: _ @operator)
+(function_identifier) @function
-(unary_op
- operator: "@" @attribute
- [(call
- function: (function_identifier) @attribute)
- (identifier) @attribute])
+(integer) @number
-(unary_op
- operator: "@"
- (call (function_identifier) @attribute
- (heredoc
- [(heredoc_start)
- (heredoc_content)
- (heredoc_end)] @string))
- (#any-of? @attribute "doc" "moduledoc"))
+(float) @float
+
+[
+ (sigil_start)
+ (sigil_end)
+] @string.special
-(unary_op
- operator: "@"
- (call (function_identifier) @attribute
- (binary_op
- left: (identifier) @method))
- (#eq? @attribute "spec"))
+; Module attributes as "attributes"
+(unary_op operator: "@" @attribute [
+ (call function: (function_identifier) @attribute)
+ (identifier) @attribute
+])
-; Definition without arguments
-(call (function_identifier) @keyword.function
- (identifier) @function
- (#lua-match? @keyword.function "^def%a*$"))
+; Erlang modules (when they are the remote of a function call) are highlighted as Elixir modules
+(dot_call remote: (atom) @type)
-; Definition with (some) arguments and (optional) defaults
-(call (function_identifier) @keyword.function
- (call
- function: (function_identifier) @function
- (arguments))
- (#lua-match? @keyword.function "^def%a*$"))
+(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
-; 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*$"))
+(call (function_identifier) @include (#any-of? @include
+ "alias"
+ "import"
+ "require"
+ "use"
+))
-; 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"))
+(call (function_identifier) @conditional (#any-of? @conditional
+ "case"
+ "cond"
+ "else"
+ "if"
+ "unless"
+ "with"
+ "receive"
+))
-(ERROR) @error
+(call (function_identifier) @exception (#any-of? @exception
+ "raise"
+ "reraise"
+ "throw"
+ "try"
+))
+
+(call (function_identifier) @repeat (#any-of? @repeat
+ "for"
+))
+
+(call (function_identifier) @keyword.function (#any-of? @keyword.function
+ "describe"
+ "setup"
+ "setup_all"
+ "test"
+ "using"
+))