Skip to content

Commit

Permalink
Add proper type to source_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 20, 2023
1 parent 15a54e1 commit 60ac913
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/ex_doc/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ defmodule ExDoc.Config do
raise ArgumentError, "#{inspect(proglang)} is not supported"
end

# TODO: The default module groups must be returned by the language
defp normalize_groups_for_modules(groups_for_modules) do
default_groups = [Deprecated: &deprecated?/1, Exceptions: &exception?/1]

Expand Down
7 changes: 4 additions & 3 deletions lib/ex_doc/nodes.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: source_doc should only be a string once we remove application/html+erlang.
defmodule ExDoc.ModuleNode do
@moduledoc false

Expand Down Expand Up @@ -35,7 +36,7 @@ defmodule ExDoc.ModuleNode do
deprecated: String.t() | nil,
doc_format: String.t() | nil,
doc: ExDoc.DocAST.t() | nil,
source_doc: term(),
source_doc: term() | nil,
rendered_doc: String.t() | nil,
doc_line: non_neg_integer(),
docs_groups: [atom()],
Expand Down Expand Up @@ -80,7 +81,7 @@ defmodule ExDoc.FunctionNode do
defaults: [function_default()],
deprecated: String.t() | nil,
doc: ExDoc.DocAST.t() | nil,
source_doc: String.t() | nil,
source_doc: term() | nil,
rendered_doc: String.t() | nil,
type: atom(),
signature: String.t(),
Expand Down Expand Up @@ -121,7 +122,7 @@ defmodule ExDoc.TypeNode do
type: atom(),
deprecated: nil,
doc: ExDoc.DocAST.t() | nil,
source_doc: String.t() | nil,
source_doc: term() | nil,
rendered_doc: String.t() | nil,
doc_line: non_neg_integer(),
source_path: String.t(),
Expand Down
18 changes: 9 additions & 9 deletions lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ defmodule ExDoc.Retriever do
annotations_for_docs
) do
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
{{type, name, arity}, anno, signature, doc_content, metadata} = doc_element
{{type, name, arity}, anno, signature, source_doc, metadata} = doc_element
doc_line = anno_line(anno)

annotations =
Expand All @@ -245,7 +245,7 @@ defmodule ExDoc.Retriever do
defaults = get_defaults(name, arity, Map.get(metadata, :defaults, 0))

doc_ast =
(doc_content && doc_ast(content_type, doc_content, file: source.path, line: doc_line + 1)) ||
(source_doc && doc_ast(content_type, source_doc, file: source.path, line: doc_line + 1)) ||
function_data.doc_fallback.()

group = GroupMatcher.match_function(groups_for_docs, metadata)
Expand All @@ -256,7 +256,7 @@ defmodule ExDoc.Retriever do
arity: arity,
deprecated: metadata[:deprecated],
doc: doc_ast,
source_doc: doc_content,
source_doc: source_doc,
doc_line: doc_line,
defaults: ExDoc.Utils.natural_sort_by(defaults, fn {name, arity} -> "#{name}/#{arity}" end),
signature: signature(signature),
Expand Down Expand Up @@ -308,7 +308,7 @@ defmodule ExDoc.Retriever do
callback_data = module_data.language.callback_data(callback, module_data)

{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
{{kind, name, arity}, anno, _signature, doc, metadata} = callback
{{kind, name, arity}, anno, _signature, source_doc, metadata} = callback
doc_line = anno_line(anno)

signature = signature(callback_data.signature)
Expand All @@ -318,7 +318,7 @@ defmodule ExDoc.Retriever do
annotations_for_docs.(metadata) ++
callback_data.extra_annotations ++ annotations_from_metadata(metadata, module_metadata)

doc_ast = doc_ast(content_type, doc, file: source.path, line: doc_line + 1)
doc_ast = doc_ast(content_type, source_doc, file: source.path, line: doc_line + 1)

metadata = Map.put(metadata, :__doc__, :callback)
group = GroupMatcher.match_function(groups_for_docs, metadata)
Expand All @@ -329,7 +329,7 @@ defmodule ExDoc.Retriever do
arity: arity,
deprecated: metadata[:deprecated],
doc: doc_ast,
source_doc: doc,
source_doc: source_doc,
doc_line: doc_line,
signature: signature,
specs: specs,
Expand All @@ -353,14 +353,14 @@ defmodule ExDoc.Retriever do

defp get_type(type_entry, source, groups_for_docs, module_data) do
{:docs_v1, _, _, content_type, _, module_metadata, _} = module_data.docs
{{_, name, arity}, anno, _signature, doc, metadata} = type_entry
{{_, name, arity}, anno, _signature, source_doc, metadata} = type_entry
doc_line = anno_line(anno)
annotations = annotations_from_metadata(metadata, module_metadata)

type_data = module_data.language.type_data(type_entry, module_data)
signature = signature(type_data.signature)
annotations = if type_data.type == :opaque, do: ["opaque" | annotations], else: annotations
doc_ast = doc_ast(content_type, doc, file: source.path, line: doc_line + 1)
doc_ast = doc_ast(content_type, source_doc, file: source.path, line: doc_line + 1)
metadata = Map.put(metadata, :__doc__, :type)
group = GroupMatcher.match_function(groups_for_docs, metadata)

Expand All @@ -372,7 +372,7 @@ defmodule ExDoc.Retriever do
spec: type_data.spec,
deprecated: metadata[:deprecated],
doc: doc_ast,
source_doc: doc,
source_doc: source_doc,
doc_line: doc_line,
signature: signature,
source_path: source.path,
Expand Down

0 comments on commit 60ac913

Please sign in to comment.