Skip to content

Commit

Permalink
Extract file from doc entry if available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
garazdawi authored and wojtekmach committed Dec 4, 2023
1 parent ae05a4f commit cbedc7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ defmodule ExDoc.Formatter.HTML do
[
id: id,
line: child_node.doc_line,
file: child_node.source_path,
current_kfa: {:function, child_node.name, child_node.arity}
]

Expand All @@ -115,6 +116,7 @@ defmodule ExDoc.Formatter.HTML do
[
id: id,
line: child_node.doc_line,
file: child_node.source_path,
current_kfa: {child_node.type, child_node.name, child_node.arity}
]

Expand Down
12 changes: 12 additions & 0 deletions lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ defmodule ExDoc.Retriever do
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
{{type, name, arity}, anno, signature, source_doc, metadata} = doc_element
doc_line = anno_line(anno)
source = anno_file(anno, source)

annotations =
annotations_for_docs.(metadata) ++
Expand Down Expand Up @@ -310,6 +311,7 @@ defmodule ExDoc.Retriever do
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
{{kind, name, arity}, anno, _signature, source_doc, metadata} = callback
doc_line = anno_line(anno)
source = anno_file(anno, source)

signature = signature(callback_data.signature)
specs = callback_data.specs
Expand Down Expand Up @@ -355,6 +357,7 @@ defmodule ExDoc.Retriever do
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
{{_, name, arity}, anno, _signature, source_doc, metadata} = type_entry
doc_line = anno_line(anno)
source = anno_file(anno, source)
annotations = annotations_from_metadata(metadata, module_metadata)

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

defp anno_file(anno, source) do
case :erl_anno.file(anno) do
:undefined ->
source
file ->
%{ url: source.url, path: Path.join(Path.dirname(source.path), file) }
end
end

defp source_link(%{path: _, url: nil}, _line), do: nil

defp source_link(source, line) do
Expand Down

0 comments on commit cbedc7d

Please sign in to comment.