Skip to content

Commit d292589

Browse files
Highlight field access differently from calls (#73)
1 parent 2c6e931 commit d292589

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

queries/highlights.scm

+30-8
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,30 @@
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+
; * remote function call
102+
(call
103+
target: (dot
104+
right: (identifier) @function))
105+
106+
; * field without parentheses or block
107+
(call
108+
target: (dot
109+
right: (identifier) @property)
110+
.)
111+
112+
; * remote call without parentheses or block (overrides above)
113+
(call
114+
target: (dot
115+
left: [
116+
(alias)
117+
(atom)
118+
]
119+
right: (identifier) @function)
120+
.)
106121

107122
; * definition keyword
108123
(call
@@ -140,6 +155,13 @@
140155
right: (identifier) @variable))
141156
(#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$"))
142157

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

145167
; * capture operand

test/highlight/calls.ex

+34
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,37 @@ 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
111+
112+
Mod.fun do
113+
# ^ module
114+
# ^ function
115+
# ^ keyword
116+
end
117+
# ^ keyword
118+
119+
mod.fun do
120+
# ^ variable
121+
# ^ function
122+
# ^ keyword
123+
end
124+
# ^ keyword

test/highlight/kernel.ex

+1-1
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)