From 4d5e000561112afd61d897997610efbbf3899175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 27 Sep 2024 23:35:52 +0700 Subject: [PATCH] Highlight field access differently from calls --- queries/highlights.scm | 38 ++++++++++++++++++++++++++++++-------- test/highlight/calls.ex | 34 ++++++++++++++++++++++++++++++++++ test/highlight/kernel.ex | 2 +- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/queries/highlights.scm b/queries/highlights.scm index c9841d3..ea6df34 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -94,15 +94,30 @@ ; Calls -; * function call +; * local function call (call - target: [ - ; local - (identifier) @function - ; remote - (dot - right: (identifier) @function) - ]) + target: (identifier) @function) + +; * remote function call +(call + target: (dot + right: (identifier) @function)) + +; * field without parentheses or block +(call + target: (dot + right: (identifier) @property) + .) + +; * remote call without parentheses or block (overrides above) +(call + target: (dot + left: [ + (alias) + (atom) + ] + right: (identifier) @function) + .) ; * definition keyword (call @@ -140,6 +155,13 @@ right: (identifier) @variable)) (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) +; * pipe into field without parentheses (function call) +(binary_operator + operator: "|>" + right: (call + target: (dot + right: (identifier) @function))) + ; Operators ; * capture operand diff --git a/test/highlight/calls.ex b/test/highlight/calls.ex index eb51f23..ea0e03e 100644 --- a/test/highlight/calls.ex +++ b/test/highlight/calls.ex @@ -88,3 +88,37 @@ end) # ^ operator # ^ number # ^ punctuation.bracket + +map.key1 +# ^ variable +# ^ property + +map.key1.key2 +# ^ variable +# ^ property +# ^ property + +DateTime.utc_now.day +# ^ module +# ^ function +# ^ property + +arg |> mod.func +# ^ variable +# ^ operator +# ^ variable +# ^ function + +Mod.fun do +# ^ module +# ^ function +# ^ keyword +end +# ^ keyword + +mod.fun do +# ^ variable +# ^ function +# ^ keyword +end +# ^ keyword diff --git a/test/highlight/kernel.ex b/test/highlight/kernel.ex index c2d188a..9c4a9de 100644 --- a/test/highlight/kernel.ex +++ b/test/highlight/kernel.ex @@ -92,7 +92,7 @@ case __ENV__.line do # ^ keyword # ^ constant.builtin # ^ operator -# ^ function +# ^ property # ^ keyword x when is_integer(x) -> x # <- variable