Skip to content

Commit 105906c

Browse files
garazdawiwojtekmach
authored andcommitted
Add support for rendering equiv metadata
1 parent d44adf7 commit 105906c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

lib/ex_doc/language/erlang.ex

+23-4
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ defmodule ExDoc.Language.Erlang do
6464

6565
@impl true
6666
def function_data(entry, module_data) do
67-
{{kind, name, arity}, _anno, _signature, doc_content, _metadata} = entry
67+
{{kind, name, arity}, _anno, _signature, doc_content, metadata} = entry
6868

6969
# TODO: Edoc on Erlang/OTP24.1+ includes private functions in
7070
# the chunk, so we manually yank them out for now.
7171
if kind == :function and doc_content != :hidden and
7272
function_exported?(module_data.module, name, arity) do
73-
function_data(name, arity, doc_content, module_data)
73+
function_data(name, arity, doc_content, module_data, metadata)
7474
else
7575
:skip
7676
end
7777
end
7878

79-
defp function_data(name, arity, _doc_content, module_data) do
79+
defp function_data(name, arity, _doc_content, module_data, metadata) do
8080
specs =
8181
case Map.fetch(module_data.private.specs, {name, arity}) do
8282
{:ok, specs} ->
@@ -93,7 +93,26 @@ defmodule ExDoc.Language.Erlang do
9393
end
9494

9595
%{
96-
doc_fallback: fn -> nil end,
96+
doc_fallback: fn ->
97+
case metadata[:equiv] do
98+
nil ->
99+
nil
100+
101+
equiv when is_binary(equiv) ->
102+
## We try to parse the equiv in order to link to the target
103+
with {:ok, toks, _} <- :erl_scan.string(:unicode.characters_to_list(equiv <> ".")),
104+
{:ok, [{:call, _, {:atom, _, func}, args}]} <- :erl_parse.parse_exprs(toks) do
105+
"Equivalent to [`#{equiv}`](`#{func}/#{length(args)}`)"
106+
else
107+
_ -> "Equivalent to `#{equiv}`"
108+
end
109+
|> ExDoc.DocAST.parse!("text/markdown")
110+
111+
equiv ->
112+
IO.warn("invalid equiv: #{inspect(equiv)}", [])
113+
nil
114+
end
115+
end,
97116
extra_annotations: [],
98117
line: nil,
99118
specs: specs

0 commit comments

Comments
 (0)