Skip to content

Commit

Permalink
Fix source line info for Erlang docs
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi authored and wojtekmach committed Dec 4, 2023
1 parent 105906c commit e67b286
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/ex_doc/language/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ defmodule ExDoc.Language.Elixir do
nil
end

defp find_function_line(module_data, {name, arity}) do
@doc false
def find_function_line(module_data, {name, arity}) do
Enum.find_value(module_data.private.abst_code, fn
{:function, anno, ^name, ^arity, _} -> anno_line(anno)
_ -> nil
Expand Down
12 changes: 7 additions & 5 deletions lib/ex_doc/language/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule ExDoc.Language.Erlang do

@behaviour ExDoc.Language

alias ExDoc.Language.Elixir, as: ExDocElixir
alias ExDoc.{Autolink, Refs}

@impl true
Expand Down Expand Up @@ -114,7 +115,7 @@ defmodule ExDoc.Language.Erlang do
end
end,
extra_annotations: [],
line: nil,
line: ExDocElixir.find_function_line(module_data, {name, arity}),
specs: specs
}
end
Expand All @@ -126,13 +127,14 @@ defmodule ExDoc.Language.Erlang do
extra_annotations =
if {name, arity} in module_data.private.optional_callbacks, do: ["optional"], else: []

specs =
{specs, anno} =
case Map.fetch(module_data.private.callbacks, {name, arity}) do
{:ok, specs} ->
[{:attribute, 0, :callback, {{name, arity}, specs}}]
{:type, anno, _, _} = hd(specs)
{[{:attribute, anno, :callback, {{name, arity}, specs}}], anno}

:error ->
[]
{[], anno}
end

%{
Expand All @@ -147,7 +149,7 @@ defmodule ExDoc.Language.Erlang do
def type_data(entry, module_data) do
{{kind, name, arity}, anno, signature, _doc, _metadata} = entry

case ExDoc.Language.Elixir.type_from_module_data(module_data, name, arity) do
case ExDocElixir.type_from_module_data(module_data, name, arity) do
%{} = map ->
%{
type: map.type,
Expand Down

0 comments on commit e67b286

Please # to comment.