diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index a0ee301e9d6..b8656a19109 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -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 -> :shell_docs.render(module, erl_docs) |> IO.puts() {:docs_v1, _, _, format, %{} = doc, metadata, _} -> @@ -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 @@ -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() _ -> @@ -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) @@ -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) diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index 7524d04e23f..80f71a44d32 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -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 @@ -1021,13 +1028,13 @@ 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 @@ -1035,22 +1042,22 @@ defmodule IEx.HelpersTest do 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."