-
Notifications
You must be signed in to change notification settings - Fork 351
In case function has no docs, use the ones from callback #641
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
Conversation
Hello, @michalmuskala! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information. |
lib/ex_doc/retriever.ex
Outdated
behaviour | ||
|> Code.get_docs(:callback_docs) | ||
|> List.keyfind({name, arity}, 0) | ||
callback_docs = if(is_nil(callback_docs), do: "", else: "\n\n#{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.
The condition of if
should not be wrapped in parentheses.
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.
I already don't like you @elixir-bot 😄
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.
We have already reported this to Credo, it should be fixed soon. :)
lib/ex_doc/retriever.ex
Outdated
end | ||
|
||
defp docstring(nil, name, arity, {:ok, behaviour}) do | ||
{{^name, ^arity}, _, :callback, 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.
What if the callback module was compiled without docs? It can be in a separate project.
I would do:
callback_docs = Code.get_docs(behaviour, :callback_docs) || []
case List.keyfind(callback_docs, {name, arity}, 0) do
{{^name, ^arity}, _, :callback, callback_docs} when is_binary(callback_docs) -> ...
test/ex_doc/retriever_test.exs
Outdated
assert Enum.at(docs, 1).doc == | ||
"Callback implementation for `c:CustomBehaviourOne.greet/1`." | ||
assert Enum.at(docs, 2).doc == | ||
"Callback implementation for `c:CustomBehaviourOne.hello/1`.\n\n" <> |
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.
I think it would be better to list this at the end, no? The question is: what do we want the summary of this function to be? I think we want to keep the callback original summary. If so, this should go to the bottom.
@michalmuskala beautiful, I have added some comments. |
Also, when we merge this, let's please do the same for |
a94f078
to
5f39d87
Compare
@josevalim I've updated the code. I decided to go for a solution where we extract the first line from the behaviour docs and keep it as the first line for the summary, injecting an additional paragraph at the beginning informing the user that it's not the documentation for the function itself, but rather the callback. |
5f39d87
to
be502ca
Compare
Also, it seems the |
@michalmuskala I would say let's keep it simple, because well, it is simpler. For example, the current code will crash if the docs contain no new lines, such as |
@michalmuskala cool, so I think for |
@josevalim I believe |
@michalmuskala good call, that part is good then! |
❤️ 💚 💙 💛 💜 |
@michalmuskala I'm curious if you run into this issue when browsing Ecto docs. I noticed that https://hexdocs.pm/ecto/Ecto.Multi.html#insert_all/5 isn't correctly autolinking to Repo docs (even after checking on ex_doc master with ecto docs fix (elixir-ecto/ecto#1815)). Perhaps it's a different issue though, but I figured it's worth asking before I look into it more |
@wojtekmach it should be |
doh, that makes sense. I will open up another doc fix on Ecto :) 2016-11-21 17:06 GMT+01:00 José Valim notifications@github.com:
Wojtek Mach |
@josevalim that was it, thanks! Btw, is it expected that iex shows diff --git a/lib/ecto/multi.ex b/lib/ecto/multi.ex
index dce9cbf..135f7eb 100644
--- a/lib/ecto/multi.ex
+++ b/lib/ecto/multi.ex
@@ -301,7 +301,7 @@ defmodule Ecto.Multi do
@doc """
Adds an insert_all operation to the multi.
- Accepts the same arguments and options as `Ecto.Repo.insert_all/3` does.
+ Accepts the same arguments and options as `c:Ecto.Repo.insert_all/3` does.
"""
@spec insert_all(t, name, schema_or_source, [entry], Keyword.t) :: t
when schema_or_source: binary | {binary | nil, binary} | Ecto.Schema.t, or maybe IEx should be taught to parse this and leave it out? |
I would leave it in because otherwise you may try to do |
As discussed over on IRC. A function that is not explicitly annotated with
@doc false
and doesn't have docs, but the callback does - will include callback docs.