Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 19 additions & 2 deletions lib/iex/lib/iex/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,11 @@ defmodule IEx.Introspection do

defp h_mod_fun_arity(mod, fun, arity) when is_atom(mod) do
{language, format, docs} = get_docs(mod, [:function, :macro])
spec = get_spec(mod, fun, arity)
doc_tuple = find_doc_with_content(docs, fun, arity)
spec = get_spec(mod, fun, arity, doc_tuple)

cond do
doc_tuple = find_doc_with_content(docs, fun, arity) ->
doc_tuple ->
print_fun(mod, language, format, doc_tuple, spec)
:ok

Expand Down Expand Up @@ -592,6 +593,22 @@ defmodule IEx.Introspection do
|> Enum.find(&has_callback?(&1, fun, arity))
end

defp get_spec(module, name, arity, doc_tuple) do
case get_spec(module, name, arity) do
[] ->
case doc_tuple do
{{_, ^name, doc_arity}, _, _, _, _} when doc_arity != arity ->
get_spec(module, name, doc_arity)

_ ->
[]
end

spec ->
spec
end
end

defp get_spec(module, name, arity) do
with {:ok, all_specs} <- Typespec.fetch_specs(module),
{_, specs} <- List.keyfind(all_specs, {name, arity}, 0) do
Expand Down
7 changes: 7 additions & 0 deletions lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,13 @@ defmodule IEx.HelpersTest do
assert capture_io(fn -> h(def) end) =~ def_h
end

test "prints spec for default arg function" do
spec = "@spec recompile([{:force, boolean()}]) :: :ok | :error | :noop"

assert capture_io(fn -> h(IEx.Helpers.recompile() / 0) end) =~ spec
assert capture_io(fn -> h(IEx.Helpers.recompile() / 1) end) =~ spec
end

test "prints sigil documentation" do
assert capture_io(fn -> h(~w//) end) =~ "Handles the sigil `~w` for list of words"
end
Expand Down
Loading