Skip to content

Commit 803d08b

Browse files
authored
Only use shell_docs for html docs (OTP26-) (#13583)
1 parent 2ee953f commit 803d08b

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

lib/iex/lib/iex/introspection.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ defmodule IEx.Introspection do
259259
case Code.ensure_loaded(module) do
260260
{:module, _} ->
261261
case Code.fetch_docs(module) do
262-
{:docs_v1, _, :erlang, _, _, _, _} = erl_docs ->
262+
# TODO remove once we require Erlang/OTP 27+
263+
{:docs_v1, _, :erlang, "application/erlang+html", _, _, _} = erl_docs ->
263264
:shell_docs.render(module, erl_docs) |> IO.puts()
264265

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

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

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

673676
_ ->
@@ -690,7 +693,8 @@ defmodule IEx.Introspection do
690693

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

725729
def t({module, type, arity}) when is_atom(module) and is_atom(type) and is_integer(arity) do
726730
case get_docs(module, [:type]) do
727-
{:erlang, _, _, erl_docs} ->
731+
# TODO remove once we require Erlang/OTP 27+
732+
{:erlang, "application/erlang+html", _, erl_docs} ->
728733
case :shell_docs.render_type(module, type, arity, erl_docs) do
729734
{:error, :type_missing} -> types_not_found_or_private("#{inspect(module)}.#{type}")
730735
chardata -> IO.puts(chardata)

lib/iex/test/iex/helpers_test.exs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,20 +341,27 @@ defmodule IEx.HelpersTest do
341341
@tag :erlang_doc
342342
test "prints Erlang module function specs" do
343343
captured = capture_io(fn -> h(:timer.sleep() / 1) end)
344-
assert captured =~ ":timer.sleep/1"
345344

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

354355
@tag :erlang_doc
355356
test "handles non-existing Erlang module function" do
356357
captured = capture_io(fn -> h(:timer.baz() / 1) end)
357-
assert captured =~ "No documentation for :timer.baz was found"
358+
359+
# TODO remove once we require Erlang/OTP 27+
360+
if System.otp_release() < "27" do
361+
assert captured =~ "No documentation for :timer.baz was found"
362+
else
363+
assert captured =~ "No documentation for :timer.baz/1 was found"
364+
end
358365
end
359366

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

1024-
# TODO Fix for OTP 27 once specs are available
1031+
# TODO remove once we require Erlang/OTP 27+
10251032
if System.otp_release() < "27" do
10261033
assert captured =~ "-type queue() :: queue(_)"
10271034
assert captured =~ "-opaque queue(Item)"
10281035
else
1029-
assert captured =~ "queue()"
1030-
assert captured =~ "queue(Item)"
1036+
assert captured =~ "@type queue() :: queue(_)"
1037+
assert captured =~ "@opaque queue(item)"
10311038
end
10321039
end
10331040

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

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

10451052
assert captured =~ "A list of binaries."
10461053

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

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

10561063
assert captured =~ "A list of binaries."

0 commit comments

Comments
 (0)