From e67b286455de80096ec2d67beede9cca2c0ee4f7 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 22 Nov 2023 13:06:03 +0100 Subject: [PATCH] Fix source line info for Erlang docs --- lib/ex_doc/language/elixir.ex | 3 ++- lib/ex_doc/language/erlang.ex | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ex_doc/language/elixir.ex b/lib/ex_doc/language/elixir.ex index 4645dff54..6c4cdec79 100644 --- a/lib/ex_doc/language/elixir.ex +++ b/lib/ex_doc/language/elixir.ex @@ -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 diff --git a/lib/ex_doc/language/erlang.ex b/lib/ex_doc/language/erlang.ex index 63f459f82..5e2b4514f 100644 --- a/lib/ex_doc/language/erlang.ex +++ b/lib/ex_doc/language/erlang.ex @@ -3,6 +3,7 @@ defmodule ExDoc.Language.Erlang do @behaviour ExDoc.Language + alias ExDoc.Language.Elixir, as: ExDocElixir alias ExDoc.{Autolink, Refs} @impl true @@ -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 @@ -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 %{ @@ -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,