Skip to content

Commit 589accf

Browse files
committed
Highlight field access differently from calls
1 parent 27efab5 commit 589accf

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

queries/highlights.scm

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,31 @@
9494

9595
; Calls
9696

97-
; * function call
97+
; * local function call
9898
(call
99-
target: [
100-
; local
101-
(identifier) @function
102-
; remote
103-
(dot
104-
right: (identifier) @function)
105-
])
99+
target: (identifier) @function)
100+
101+
; * field without parentheses
102+
(call
103+
target: (dot
104+
right: (identifier) @property)
105+
.)
106+
107+
; * remote call without parentheses (overrides above)
108+
(call
109+
target: (dot
110+
left: [
111+
(alias)
112+
(atom)
113+
]
114+
right: (identifier) @function)
115+
.)
116+
117+
; * remote function call with parentheses
118+
(call
119+
target: (dot
120+
right: (identifier) @function)
121+
(arguments))
106122

107123
; * definition keyword
108124
(call
@@ -140,6 +156,13 @@
140156
right: (identifier) @variable))
141157
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
142158

159+
; * pipe into field without parentheses (function call)
160+
(binary_operator
161+
operator: "|>"
162+
right: (call
163+
target: (dot
164+
right: (identifier) @function)))
165+
143166
; Operators
144167

145168
; * capture operand

test/highlight/calls.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,23 @@ end)
8888
# ^ operator
8989
# ^ number
9090
# ^ punctuation.bracket
91+
92+
map.key1
93+
# ^ variable
94+
# ^ property
95+
96+
map.key1.key2
97+
# ^ variable
98+
# ^ property
99+
# ^ property
100+
101+
DateTime.utc_now.day
102+
# ^ module
103+
# ^ function
104+
# ^ property
105+
106+
arg |> mod.func
107+
# ^ variable
108+
# ^ operator
109+
# ^ variable
110+
# ^ function

test/highlight/kernel.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ case __ENV__.line do
9292
# ^ keyword
9393
# ^ constant.builtin
9494
# ^ operator
95-
# ^ function
95+
# ^ property
9696
# ^ keyword
9797
x when is_integer(x) -> x
9898
# <- variable

0 commit comments

Comments
 (0)