From 5822de7fba0453e1b2d7558a0b3c77828fa115e3 Mon Sep 17 00:00:00 2001 From: Stephen Bolton Date: Tue, 7 Feb 2023 22:52:52 -0500 Subject: [PATCH] fix(elixir): separate function from parameter matching 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 focus on the specifics of fulfilling each query. This should resolve issue #249. --- queries/elixir/textobjects.scm | 50 +++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/queries/elixir/textobjects.scm b/queries/elixir/textobjects.scm index e81a2a91..a91a87a6 100644 --- a/queries/elixir/textobjects.scm +++ b/queries/elixir/textobjects.scm @@ -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" @@ -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" @@ -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))