-
Notifications
You must be signed in to change notification settings - Fork 351
Copy callback typespecs #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,18 +239,9 @@ defmodule ExDoc.Retriever do | |
function = actual_def(name, arity, type) | ||
line = find_actual_line(module_info.abst_code, function, :function) || doc_line | ||
|
||
doc = docstring(doc, name, arity, Map.fetch(module_info.impls, {name, arity})) | ||
|
||
specs = module_info.specs | ||
|> Map.get(function, []) | ||
|> Enum.map(&Typespec.spec_to_ast(name, &1)) | ||
|
||
specs = | ||
if type == :defmacro do | ||
Enum.map(specs, &remove_first_macro_arg/1) | ||
else | ||
specs | ||
end | ||
impl = Map.fetch(module_info.impls, {name, arity}) | ||
doc = docstring(doc, name, arity, impl) | ||
specs = get_specs(module_info, type, function, name, arity, impl) | ||
|
||
annotations = | ||
case {type, name, arity} do | ||
|
@@ -297,6 +288,31 @@ defmodule ExDoc.Retriever do | |
end | ||
end | ||
|
||
defp get_specs(module_info, type, function, name, arity, impl) do | ||
specs = | ||
module_info.specs | ||
|> Map.get(function, []) | ||
|> Enum.map(&Typespec.spec_to_ast(name, &1)) | ||
|
||
specs = | ||
if type == :defmacro do | ||
Enum.map(specs, &remove_first_macro_arg/1) | ||
else | ||
specs | ||
end | ||
|
||
copy_callback_specs(specs, name, arity, impl) | ||
end | ||
|
||
defp copy_callback_specs([], name, arity, {:ok, behaviour}) do | ||
callbacks = Kernel.Typespec.beam_callbacks(behaviour) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is private API :( any other options? |
||
{_, specs} = List.keyfind(callbacks, {name, arity}, 0) | ||
Enum.map(specs, &Typespec.spec_to_ast(name, &1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in similar code in IEx [1] we're doing [1] https://github.com/elixir-lang/elixir/blob/v1.5.3/lib/iex/lib/iex/introspection.ex#L434 |
||
end | ||
defp copy_callback_specs(specs, _, _, _) do | ||
specs | ||
end | ||
|
||
defp docstring(nil, name, arity, {:ok, behaviour}) do | ||
info = "Callback implementation for `c:#{inspect behaviour}.#{name}/#{arity}`." | ||
callback_docs = Code.get_docs(behaviour, :callback_docs) || [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function takes too many parameters (arity is 6, max is 5).