Skip to content

Commit

Permalink
fix(elixir): separate function from parameter matching
Browse files Browse the repository at this point in the history
Previous queries were mixing the parameter matches and the function
matches into the same query. This would make it so that functions that
didn't have parameters wouldn't match @function.inner or @function.outer
queries.

Separating them makes it easier to handle each case more specifically
and focus on the specifics of fulfilling that query. This should resolve
issue #249.
  • Loading branch information
skbolton committed Feb 8, 2023
1 parent 5ebf16f commit b2f62b2
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions queries/elixir/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@
(do_block "do" . (_) @class.inner . "end")
) @class.outer

; Function, Parameter, and Call Objects
; Parameters
(call
target: ((identifier) @_identifier (#any-of? @_identifier
"def"
"defmacro"
"defmacrop"
"defn"
"defnp"
"defp"
))
(arguments (call [
(arguments (_) @parameter.inner . "," @_delimiter)
(arguments ((_) @parameter.inner) @_delimiter .)
] (#make-range! "parameter.outer" @parameter.inner @_delimiter)))
) @function.outer

; Function and Call Objects
(anonymous_function
(stab_clause
right: (body) @function.inner)
) @function.outer

; single child
(call
target: ((identifier) @_identifier (#any-of? @_identifier
"def"
Expand All @@ -43,17 +60,26 @@
"defnp"
"defp"
))
(arguments (call [
(arguments (_) @parameter.inner . "," @_delimiter)
(arguments ((_) @parameter.inner) @_delimiter .)
] (#make-range! "parameter.outer" @parameter.inner @_delimiter)))
[
(do_block "do" . (_) @_do (_) @_end . "end")
(do_block "do" . ((_) @_do) @_end . "end")
]
(arguments (call))
(do_block "do" . (_) @function.inner . "end")
) @function.outer

; multi child
(call
target: ((identifier) @_identifier (#any-of? @_identifier
"def"
"defmacro"
"defmacrop"
"defn"
"defnp"
"defp"
))
(arguments (call))
(do_block "do" . (_) @_do (_) @_end . "end")
(#make-range! "function.inner" @_do @_end)
) @function.outer

; def function(), do: ....
(call
target: ((identifier) @_identifier (#any-of? @_identifier
"def"
Expand All @@ -63,10 +89,8 @@
"defnp"
"defp"
))
(arguments (call [
(arguments (_) @parameter.inner . "," @_delimiter)
(arguments ((_) @parameter.inner) @_delimiter .)
] (#make-range! "parameter.outer" @parameter.inner @_delimiter))
(arguments
(call)
(keywords
(pair
value: (_) @function.inner))
Expand Down

0 comments on commit b2f62b2

Please sign in to comment.