Skip to content

Commit

Permalink
Autolink support for handling remote types in records
Browse files Browse the repository at this point in the history
  • Loading branch information
starbelly committed Sep 9, 2023
1 parent 960e2ef commit 98d9b69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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]}

{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}

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

0 comments on commit 98d9b69

Please sign in to comment.