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

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/b210d5c0-e21f-4bf1-8a8e-6a8f5cf89d97o%40googlegroups.com.

Reply via email to