[Proposal] IEX help in place with tab key

93 views
Skip to first unread message

Brian Gomes Bascoy

unread,
Sep 16, 2020, 3:51:09 AM9/16/20
to elixir-lang-core
Problem:

My memory is quite awful and sometimes while I'm typing a long pipeline I realize I'm not sure about the order of some parameters, so then I have to copy everything I have typed so far, remove all the text up to the last function call (i.e. the one that I don't remember its definition), add an h at the beginning of the line, read the docs (maybe even scroll up because of docs being too extensive), delete everything and finally paste what I have on my clipboard to finish my function call.


Solution:

IEx docs/signature/spec in place with tab key! :D I basically hacked my IEx so when you press the tab key after an expression like "Enum.reduce(" or "Enum.reduce " the shell will show you a list of definitions for the function at the left of your cursor.

It only requires some trivial additions in IEx.Autocomplete. Here is a prototype:

defp get_signatures(module, name) do
  {:docs_v1, _, _, _, _, _, docs} = Code.fetch_docs(module)

  signatures =
    docs
    |> Enum.filter(&match?({{:function, ^name, _}, _, _, _, _}, &1))
    |> Enum.map(fn {_, _, [signature], _, _} -> signature end)
    |> Enum.join("\n")

  yes("", [signatures])
end

defp expand_help(expr, _server) do
  case Code.string_to_quoted(expr) do
    {:ok, {{:., _, [{:__aliases__, _, aliases}, fun]}, _, []}} when is_atom(fun) ->
      try do
        get_signatures(Module.safe_concat(aliases), fun)
      rescue
        _ -> no()
      end

    _ ->
      no()
  end
end

# And it also needs a minimal change in expand/2:
h in '[{' -> expand('')
h in ' (' -> expand_help(reduce(expr), server)


I also wrote a version that prints specs but sometimes that can be too verbose/noisy, so I'm still not sure which one do I prefer.

Let me know what do you think.

Thanks

Boris Kuznetsov

unread,
Sep 16, 2020, 7:38:56 AM9/16/20
to elixir-l...@googlegroups.com
To me this sounds great.

Although I use separate documentation app I think this could make iex
more user friendly for new developers as well.

Brian Gomes Bascoy

unread,
Sep 17, 2020, 3:10:37 AM9/17/20
to elixir-lang-core
Thank you, I'm glad you like it! There are a few issues with that proof of concept (dealing with imported functions for instance), but I already have a more robust version on my dev machine. If people find this feature useful I can write a few test cases and submit a PR.

cheers

José Valim

unread,
Sep 17, 2020, 3:13:16 AM9/17/20
to elixir-l...@googlegroups.com
Hi Brian, Can you please submit a PR with the WIP? Then we can ask people to try it out... this is one of the things that may be better giving it a try in practice. Then if we believe it is better, we can clean it up. Thank you!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6f85e6d1-50e3-4d28-bdfe-74d024eb60bco%40googlegroups.com.

Brian Gomes Bascoy

unread,
Sep 17, 2020, 3:51:29 AM9/17/20
to elixir-lang-core

thanks

On Thursday, September 17, 2020 at 12:13:16 AM UTC-7, José Valim wrote:
Hi Brian, Can you please submit a PR with the WIP? Then we can ask people to try it out... this is one of the things that may be better giving it a try in practice. Then if we believe it is better, we can clean it up. Thank you!

On Thu, Sep 17, 2020 at 9:10 AM Brian Gomes Bascoy <gomes...@gmail.com> wrote:
Thank you, I'm glad you like it! There are a few issues with that proof of concept (dealing with imported functions for instance), but I already have a more robust version on my dev machine. If people find this feature useful I can write a few test cases and submit a PR.

cheers

On Wednesday, September 16, 2020 at 4:38:56 AM UTC-7, Boris Kuznetsov wrote:
To me this sounds great.

Although I use separate documentation app I think this could make iex
more user friendly for new developers as well.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-l...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages