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

add textobject queries for beam languages, capture rust closures as functions #2661

Merged
merged 4 commits into from
Jun 7, 2022

Conversation

the-mikedavis
Copy link
Member

@the-mikedavis the-mikedavis commented Jun 3, 2022

Adds textobject queries for Erlang, Elixir & Gleam

Also includes an update for tree-sitter-erlang that makes function_clause a named node.

Erlang and Elixir may have multiple function clauses for one function:

fib(0) -> 0;                                %% one textobj, ]f selects this line
fib(1) -> 1;                                %% this line is another
fib(N) when N > 0 -> fib(N-1) + fib(N-2).   %% and this line is another

In these queries I'm capturing function clauses as function.around but I'm curious if others think it should be around the entire function definition.

Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

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

Ah, I didn't realized textobjects is specifically used for this. Looks good to me although I didn't check closely.

@archseer
Copy link
Member

archseer commented Jun 3, 2022

In these queries I'm capturing function clauses as function.around but I'm curious if others think it should be around the entire function definition.

Since this is Elixir/Erlang-specific @connorlay, wdyt? 😀

I imagine the issue could be that clauses aren't always defined next to each other

@connorlay
Copy link
Contributor

In these queries I'm capturing function clauses as function.around but I'm curious if others think it should be around the entire function definition.

Elixir supports multiple function heads like this:

def foo(:bar) do
  "bar"
end

def foo(:baz) do
  "baz"
end

...which I would consider two separate textobjects. However, if written as an anonymous function with multiple clauses like this:

foo = fn
  :bar -> "bar"
  :baz -> "baz"
end

I would consider that one textobject. Does that make sense @the-mikedavis @archseer ?

@the-mikedavis
Copy link
Member Author

I added queries for anonymous functions as well, so:

fn
  :ok -> 1
  :error -> 2
end

]f/maf selects the whole anonymous function and mif selects the body of each clause, so 1 for the first clause and 2 for the second.

We could probably do the same for rust closures, eh?

@archseer
Copy link
Member

archseer commented Jun 6, 2022

We could probably do the same for rust closures, eh?

Yup!

Closures like

    iter.map(|a| a + 1)

Are sort-of functions, so `]f` or `maf` or `mif` can apply to them
as well as named function definitions.
@the-mikedavis the-mikedavis changed the title add textobject queries for beam languages add textobject queries for beam languages, capture rust closures as functions Jun 6, 2022
@archseer archseer merged commit 4a27e2d into helix-editor:master Jun 7, 2022
@the-mikedavis the-mikedavis deleted the md-beam-textobjects branch June 7, 2022 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants