diff --git a/lib/ex_doc/language.ex b/lib/ex_doc/language.ex index 0a55a5eea..67e4b0e91 100644 --- a/lib/ex_doc/language.ex +++ b/lib/ex_doc/language.ex @@ -24,8 +24,10 @@ defmodule ExDoc.Language do * `:callback_types` - a list of types that are considered callbacks - * `:nesting_info` - A `{nested_title, nested_context}` tuple or `nil`. + * `:nesting_info` - a `{nested_title, nested_context}` tuple or `nil`. For example, `"A.B.C"` becomes `{"C", "A.B"}`. + + * `:private` - a map with language-specific data """ @type module_data() :: %{ module: module(), @@ -37,7 +39,8 @@ defmodule ExDoc.Language do skip: boolean(), line: non_neg_integer(), callback_types: [atom()], - nesting_info: {String.t(), String.t()} | nil + nesting_info: {String.t(), String.t()} | nil, + private: map() } @doc """ diff --git a/lib/ex_doc/language/elixir.ex b/lib/ex_doc/language/elixir.ex index d1631aa4b..d51a60245 100644 --- a/lib/ex_doc/language/elixir.ex +++ b/lib/ex_doc/language/elixir.ex @@ -24,13 +24,15 @@ defmodule ExDoc.Language.Elixir do title: title, type: type, skip: skip, + line: line, callback_types: [:callback, :macrocallback], nesting_info: nesting_info(title, config.nest_modules_by_prefix), - line: line, - abst_code: abst_code, - specs: Erlang.get_specs(module), - callbacks: Erlang.get_callbacks(module), - impls: get_impls(module) + private: %{ + abst_code: abst_code, + specs: Erlang.get_specs(module), + callbacks: Erlang.get_callbacks(module), + impls: get_impls(module) + } } end @@ -49,7 +51,7 @@ defmodule ExDoc.Language.Elixir do %{ doc_fallback: fn -> - impl = Map.fetch(module_data.impls, actual_def) + impl = Map.fetch(module_data.private.impls, actual_def) callback_doc_ast(name, arity, impl) || delegate_doc_ast(metadata[:delegate_to]) @@ -66,7 +68,7 @@ defmodule ExDoc.Language.Elixir do actual_def = actual_def(name, arity, kind) specs = - case Map.fetch(module_data.callbacks, actual_def) do + case Map.fetch(module_data.private.callbacks, actual_def) do {:ok, specs} -> specs @@ -111,7 +113,7 @@ defmodule ExDoc.Language.Elixir do @doc false def type_from_module_data(module_data, name, arity) do - Enum.find_value(module_data.abst_code, fn + Enum.find_value(module_data.private.abst_code, fn {:attribute, anno, type, {^name, _, args} = spec} -> if type in [:opaque, :type] and length(args) == arity do %{ @@ -218,7 +220,7 @@ defmodule ExDoc.Language.Elixir do defp specs(kind, name, actual_def, module_data) do specs = - module_data.specs + module_data.private.specs |> Map.get(actual_def, []) |> Enum.map(&Code.Typespec.spec_to_quoted(name, &1)) @@ -273,8 +275,8 @@ defmodule ExDoc.Language.Elixir do nil end - defp find_function_line(%{abst_code: abst_code}, {name, arity}) do - Enum.find_value(abst_code, fn + defp 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 end) diff --git a/lib/ex_doc/language/erlang.ex b/lib/ex_doc/language/erlang.ex index 92ea49ba9..a0e487a58 100644 --- a/lib/ex_doc/language/erlang.ex +++ b/lib/ex_doc/language/erlang.ex @@ -19,12 +19,14 @@ defmodule ExDoc.Language.Erlang do title: id, type: module_type(module), skip: false, + line: line, callback_types: [:callback], nesting_info: nil, - line: line, - abst_code: abst_code, - specs: get_specs(module), - callbacks: get_callbacks(module) + private: %{ + abst_code: abst_code, + specs: get_specs(module), + callbacks: get_callbacks(module) + } } end @@ -33,7 +35,7 @@ defmodule ExDoc.Language.Erlang do {{_kind, name, arity}, _anno, _signature, _doc_content, _metadata} = entry specs = - case Map.fetch(module_data.specs, {name, arity}) do + case Map.fetch(module_data.private.specs, {name, arity}) do {:ok, specs} -> [{:attribute, 0, :spec, {{name, arity}, specs}}] @@ -54,7 +56,7 @@ defmodule ExDoc.Language.Erlang do {{_kind, name, arity}, anno, signature, _doc, _metadata} = entry specs = - case Map.fetch(module_data.callbacks, {name, arity}) do + case Map.fetch(module_data.private.callbacks, {name, arity}) do {:ok, specs} -> [{:attribute, 0, :callback, {{name, arity}, specs}}]