Skip to content

Commit

Permalink
Highlight field access differently from calls (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Sep 28, 2024
1 parent 2c6e931 commit d292589
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
38 changes: 30 additions & 8 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/highlight/calls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/highlight/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ case __ENV__.line do
# ^ keyword
# ^ constant.builtin
# ^ operator
# ^ function
# ^ property
# ^ keyword
x when is_integer(x) -> x
# <- variable
Expand Down

0 comments on commit d292589

Please sign in to comment.