Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elixir): separate function from parameter matching #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(arguments (call))
(arguments ([
(call)
(identifier)
(binary_operator)
]))

(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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(arguments (call))
(arguments ([
(call)
(identifier)
(binary_operator)
]))

(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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(call)
([
(call)
(identifier)
(binary_operator)
])

(keywords
(pair
value: (_) @function.inner))
Expand Down