Skip to content

Commit

Permalink
Autolink support for handling remote types in records (#1763)
Browse files Browse the repository at this point in the history
  • Loading branch information
starbelly authored Sep 25, 2023
1 parent 3d85467 commit 16a8f53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/ex_doc/language/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ defmodule ExDoc.Language.Erlang do
{:->, _, [[{name, _, _}], {:any, _, _}]}, acc when name == :... ->
{nil, acc}

# record{type :: remote:type/arity}
{:field_type, _, [name, {{:., _, [r_mod, r_type]}, _, args}]}, acc ->
{name, [{pp({r_mod, r_type}), {r_mod, r_type, length(args)}} | acc]}

# #{x :: t()}
{:field_type, _, [name, type]}, acc when is_atom(name) ->
{type, acc}
Expand Down
12 changes: 11 additions & 1 deletion 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, t2/0]).
%% @doc
%% f/0 function.
Expand All @@ -29,6 +29,10 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do
-type t() :: atom().
%% t/0 type.
-record(rec, {k1 :: any(), k2 :: any()}).
-type t2() :: #rec{k1 :: uri_string:uri_string(), k2 :: uri_string:uri_string() | undefined}.
""")

doc = generate_docs(c)
Expand All @@ -38,6 +42,12 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do

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

assert "-type t2() :: #rec{k1 :: uri_string:uri_string(), k2 :: uri_string:uri_string() | undefined}."

doc
|> Floki.find("pre:fl-contains('t2() ::')")
|> Floki.text()
end

defp generate_docs(c) do
Expand Down

0 comments on commit 16a8f53

Please sign in to comment.