Skip to content

Commit cbedc7d

Browse files
garazdawiwojtekmach
authored andcommitted
Extract file from doc entry if available
The documentation could be in an include file, then the file in the moduledoc anno would be different than the file in the doc anno. Normally this does not matter except for when we need to create a warning for a broken link.
1 parent ae05a4f commit cbedc7d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/ex_doc/formatter/html.ex

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ defmodule ExDoc.Formatter.HTML do
9898
[
9999
id: id,
100100
line: child_node.doc_line,
101+
file: child_node.source_path,
101102
current_kfa: {:function, child_node.name, child_node.arity}
102103
]
103104

@@ -115,6 +116,7 @@ defmodule ExDoc.Formatter.HTML do
115116
[
116117
id: id,
117118
line: child_node.doc_line,
119+
file: child_node.source_path,
118120
current_kfa: {child_node.type, child_node.name, child_node.arity}
119121
]
120122

lib/ex_doc/retriever.ex

+12
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ defmodule ExDoc.Retriever do
236236
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
237237
{{type, name, arity}, anno, signature, source_doc, metadata} = doc_element
238238
doc_line = anno_line(anno)
239+
source = anno_file(anno, source)
239240

240241
annotations =
241242
annotations_for_docs.(metadata) ++
@@ -310,6 +311,7 @@ defmodule ExDoc.Retriever do
310311
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
311312
{{kind, name, arity}, anno, _signature, source_doc, metadata} = callback
312313
doc_line = anno_line(anno)
314+
source = anno_file(anno, source)
313315

314316
signature = signature(callback_data.signature)
315317
specs = callback_data.specs
@@ -355,6 +357,7 @@ defmodule ExDoc.Retriever do
355357
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
356358
{{_, name, arity}, anno, _signature, source_doc, metadata} = type_entry
357359
doc_line = anno_line(anno)
360+
source = anno_file(anno, source)
358361
annotations = annotations_from_metadata(metadata, module_metadata)
359362

360363
type_data = module_data.language.type_data(type_entry, module_data)
@@ -406,6 +409,15 @@ defmodule ExDoc.Retriever do
406409
defp anno_line(line) when is_integer(line), do: abs(line)
407410
defp anno_line(anno), do: anno |> :erl_anno.line() |> abs()
408411

412+
defp anno_file(anno, source) do
413+
case :erl_anno.file(anno) do
414+
:undefined ->
415+
source
416+
file ->
417+
%{ url: source.url, path: Path.join(Path.dirname(source.path), file) }
418+
end
419+
end
420+
409421
defp source_link(%{path: _, url: nil}, _line), do: nil
410422

411423
defp source_link(source, line) do

0 commit comments

Comments
 (0)