Skip to content

Only use shell_docs for html docs (OTP26-) #13583

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

Merged
merged 3 commits into from
May 21, 2024
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
15 changes: 10 additions & 5 deletions lib/iex/lib/iex/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ defmodule IEx.Introspection do
case Code.ensure_loaded(module) do
{:module, _} ->
case Code.fetch_docs(module) do
{:docs_v1, _, :erlang, _, _, _, _} = erl_docs ->
# TODO remove once we require Erlang/OTP 27+
{:docs_v1, _, :erlang, "application/erlang+html", _, _, _} = erl_docs ->
Copy link
Member

Choose a reason for hiding this comment

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

We should add a TODO to remove support for "application/erlang+html" once we are on OTP 27+.

:shell_docs.render(module, erl_docs) |> IO.puts()

{:docs_v1, _, _, format, %{} = doc, metadata, _} ->
Expand Down Expand Up @@ -378,7 +379,8 @@ defmodule IEx.Introspection do
spec = get_spec(mod, fun, arity)

cond do
language == :erlang ->
# TODO remove once we require Erlang/OTP 27+
language == :erlang and format == "application/erlang+html" ->
print_erlang_doc(mod, fun, arity, docs_v1)
:ok

Expand Down Expand Up @@ -667,7 +669,8 @@ defmodule IEx.Introspection do
"""
def t(module) when is_atom(module) do
case :code.get_doc(module) do
{:ok, {:docs_v1, _, :erlang, _, _, _, _} = erl_docs} ->
# TODO remove once we require Erlang/OTP 27+
{:ok, {:docs_v1, _, :erlang, "application/erlang+html", _, _, _} = erl_docs} ->
:shell_docs.render_type(module, erl_docs) |> IO.puts()

_ ->
Expand All @@ -690,7 +693,8 @@ defmodule IEx.Introspection do

def t({module, type}) when is_atom(module) and is_atom(type) do
case get_docs(module, [:type]) do
{:erlang, _, _, erl_docs} ->
# TODO remove once we require Erlang/OTP 27+
{:erlang, "application/erlang+html", _, erl_docs} ->
case :shell_docs.render_type(module, type, erl_docs) do
{:error, :type_missing} -> types_not_found_or_private("#{inspect(module)}.#{type}")
iodata -> IO.puts(iodata)
Expand Down Expand Up @@ -724,7 +728,8 @@ defmodule IEx.Introspection do

def t({module, type, arity}) when is_atom(module) and is_atom(type) and is_integer(arity) do
case get_docs(module, [:type]) do
{:erlang, _, _, erl_docs} ->
# TODO remove once we require Erlang/OTP 27+
{:erlang, "application/erlang+html", _, erl_docs} ->
case :shell_docs.render_type(module, type, arity, erl_docs) do
{:error, :type_missing} -> types_not_found_or_private("#{inspect(module)}.#{type}")
chardata -> IO.puts(chardata)
Expand Down
27 changes: 17 additions & 10 deletions lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,27 @@ defmodule IEx.HelpersTest do
@tag :erlang_doc
test "prints Erlang module function specs" do
captured = capture_io(fn -> h(:timer.sleep() / 1) end)
assert captured =~ ":timer.sleep/1"

# TODO Fix for OTP 27 once specs are available
# TODO remove once we require Erlang/OTP 27+
if System.otp_release() < "27" do
assert captured =~ ":timer.sleep/1"
assert captured =~ "-spec sleep(Time) -> ok when Time :: timeout()."
else
assert captured =~ "sleep(Time)"
assert captured =~ "@spec sleep(time) :: :ok when time: timeout()"
end
end

@tag :erlang_doc
test "handles non-existing Erlang module function" do
captured = capture_io(fn -> h(:timer.baz() / 1) end)
assert captured =~ "No documentation for :timer.baz was found"

# TODO remove once we require Erlang/OTP 27+
if System.otp_release() < "27" do
assert captured =~ "No documentation for :timer.baz was found"
else
assert captured =~ "No documentation for :timer.baz/1 was found"
end
end

test "prints module documentation" do
Expand Down Expand Up @@ -1021,36 +1028,36 @@ defmodule IEx.HelpersTest do
test "prints all types in Erlang module" do
captured = capture_io(fn -> t(:queue) end)

# TODO Fix for OTP 27 once specs are available
# TODO remove once we require Erlang/OTP 27+
if System.otp_release() < "27" do
assert captured =~ "-type queue() :: queue(_)"
assert captured =~ "-opaque queue(Item)"
else
assert captured =~ "queue()"
assert captured =~ "queue(Item)"
assert captured =~ "@type queue() :: queue(_)"
assert captured =~ "@opaque queue(item)"
end
end

@tag :erlang_doc
test "prints single type from Erlang module" do
captured = capture_io(fn -> t(:erlang.iovec()) end)

# TODO Fix for OTP 27 once specs are available
# TODO remove once we require Erlang/OTP 27+
if System.otp_release() < "27" do
assert captured =~ "-type iovec() :: [binary()]"
else
assert captured =~ "iovec()"
assert captured =~ "@type iovec() :: [binary()]"
end

assert captured =~ "A list of binaries."

captured = capture_io(fn -> t(:erlang.iovec() / 0) end)

# TODO Fix for OTP 27 once specs are available
# TODO remove once we require Erlang/OTP 27+
if System.otp_release() < "27" do
assert captured =~ "-type iovec() :: [binary()]"
else
assert captured =~ "iovec()"
assert captured =~ "@type iovec() :: [binary()]"
end

assert captured =~ "A list of binaries."
Expand Down