Skip to content

Commit b630899

Browse files
garazdawiwojtekmach
authored andcommitted
Allow annotations_for_docs for types
1 parent cbedc7d commit b630899

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/ex_doc/retriever.ex

+11-6
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ defmodule ExDoc.Retriever do
150150
function_docs ++
151151
get_callbacks(module_data, source, groups_for_docs, annotations_for_docs)
152152

153-
types = get_types(module_data, source, groups_for_docs)
153+
types = get_types(module_data, source, groups_for_docs, annotations_for_docs)
154154

155155
metadata = Map.put(metadata, :__doc__, module_data.type)
156156
group = GroupMatcher.match_module(config.groups_for_modules, module, module_data.id, metadata)
@@ -345,15 +345,15 @@ defmodule ExDoc.Retriever do
345345

346346
## Typespecs
347347

348-
defp get_types(module_data, source, groups_for_docs) do
348+
defp get_types(module_data, source, groups_for_docs, annotations_for_docs) do
349349
{:docs_v1, _, _, _, _, _, docs} = module_data.docs
350350

351351
for {{:type, _, _}, _, _, content, _} = doc <- docs, content != :hidden do
352-
get_type(doc, source, groups_for_docs, module_data)
352+
get_type(doc, source, groups_for_docs, module_data, annotations_for_docs)
353353
end
354354
end
355355

356-
defp get_type(type_entry, source, groups_for_docs, module_data) do
356+
defp get_type(type_entry, source, groups_for_docs, module_data, annotations_for_docs) do
357357
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
358358
{{_, name, arity}, anno, _signature, source_doc, metadata} = type_entry
359359
doc_line = anno_line(anno)
@@ -362,7 +362,11 @@ defmodule ExDoc.Retriever do
362362

363363
type_data = module_data.language.type_data(type_entry, module_data)
364364
signature = signature(type_data.signature)
365-
annotations = if type_data.type == :opaque, do: ["opaque" | annotations], else: annotations
365+
366+
annotations =
367+
annotations_for_docs.(metadata) ++
368+
if type_data.type == :opaque, do: ["opaque" | annotations], else: annotations
369+
366370
doc_ast = doc_ast(content_type, source_doc, file: source.path, line: doc_line + 1)
367371
metadata = Map.put(metadata, :__doc__, :type)
368372
group = GroupMatcher.match_function(groups_for_docs, metadata)
@@ -413,8 +417,9 @@ defmodule ExDoc.Retriever do
413417
case :erl_anno.file(anno) do
414418
:undefined ->
415419
source
420+
416421
file ->
417-
%{ url: source.url, path: Path.join(Path.dirname(source.path), file) }
422+
%{url: source.url, path: Path.join(Path.dirname(source.path), file)}
418423
end
419424
end
420425

0 commit comments

Comments
 (0)