Skip to content
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

Autolink support for handling remote types in records #1763

4 changes: 4 additions & 0 deletions lib/ex_doc/language/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ defmodule ExDoc.Language.Erlang do
{{:., _, [module, name]}, _, args}, acc ->
{{:t, [], args}, [{pp({module, name}), {module, name, length(args)}} | acc]}

## type module.type/0
{:., _, [module, name]} = ast, acc ->
{ast, [{pp({module, name}), {module, name, 0}} | acc]}
starbelly marked this conversation as resolved.
Show resolved Hide resolved

{name, _, _}, acc when name in [:<<>>, :..] ->
{nil, acc}

Expand Down
20 changes: 18 additions & 2 deletions test/ex_doc/formatter/html/erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do
%% foo module.
-module(foo).
-export([foo/1, bar/0]).
-export_type([t/0]).
-export_type([t/0, my_tea/0]).

%% @doc
%% f/0 function.
Expand All @@ -29,15 +29,31 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do

-type t() :: atom().
%% t/0 type.

-record(some_record, {bar :: undefined, foo :: undefined}).

-type my_tea() :: #some_record{bar :: uri_string:uri_string(), foo :: uri_string:uri_string() | undefine}.

-spec baz() -> my_tea().
baz() ->
Eh = <<"eh?">>,
#some_record{bar=Eh,foo=undefined}.
""")

doc = generate_docs(c)
refute ExUnit.CaptureIO.capture_io(:stderr, fn ->
send(self(), {:doc_path, generate_docs(c)})
end) =~ "inconsistency, please submit bug"

assert_received {:doc_path, doc}
starbelly marked this conversation as resolved.
Show resolved Hide resolved

assert "-spec foo(atom()) -> atom()." =
doc |> Floki.find("pre:fl-contains('foo(atom())')") |> Floki.text()

assert "-type t() :: atom()." =
doc |> Floki.find("pre:fl-contains('t() :: atom().')") |> Floki.text()

# assert "-type my_tea() :: atom()." =
# doc |> Floki.find("pre:fl-contains('my_tea() :: atom().')") |> Floki.text()
end

defp generate_docs(c) do
Expand Down