Skip to content

Conversation

michalmuskala
Copy link
Member

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.

@elixir-bot
Copy link

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.

behaviour
|> Code.get_docs(:callback_docs)
|> List.keyfind({name, arity}, 0)
callback_docs = if(is_nil(callback_docs), do: "", else: "\n\n#{callback_docs}")

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.

Copy link
Member

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 😄

Copy link
Member

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. :)

end

defp docstring(nil, name, arity, {:ok, behaviour}) do
{{^name, ^arity}, _, :callback, callback_docs} =
Copy link
Member

@josevalim josevalim Nov 14, 2016

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) -> ...

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" <>
Copy link
Member

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.

@josevalim
Copy link
Member

@michalmuskala beautiful, I have added some comments.

@josevalim
Copy link
Member

Also, when we merge this, let's please do the same for IEx.Helpers.h. :)

@michalmuskala michalmuskala force-pushed the callback-docs branch 2 times, most recently from a94f078 to 5f39d87 Compare November 16, 2016 08:15
@michalmuskala
Copy link
Member Author

@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.

@michalmuskala
Copy link
Member Author

Also, it seems the h helper already has something similar: https://github.com/elixir-lang/elixir/blob/master/lib/iex/test/iex/helpers_test.exs#L76-L108

@josevalim
Copy link
Member

@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 @doc "foo" and it is splitting on new lines while it should be on \n\n. None of those would matter if we always add the note to the end, which I believe is better and simpler.

@josevalim
Copy link
Member

@michalmuskala cool, so I think for h we just need to add a notice to the end that says "Implementation for callback x.y/z"?

@michalmuskala
Copy link
Member Author

@josevalim I believe h will print the @callback foo(...) banner instead of def foo(...) when printing callback docs, so we may be fine.

@josevalim
Copy link
Member

@michalmuskala good call, that part is good then!

@josevalim josevalim merged commit 43d5af7 into elixir-lang:master Nov 18, 2016
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

@wojtekmach
Copy link
Member

wojtekmach commented Nov 21, 2016

@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

@josevalim
Copy link
Member

@wojtekmach it should be c:Ecto.Repo.insert_all/4 so it is a bug in Ecto's documentation. :)

@wojtekmach
Copy link
Member

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:

@wojtekmach https://github.com/wojtekmach it should be
c:Ecto.Repo.insert_all/4 so it is a bug in Ecto's documentation. :)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#641 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEpJ1qiqrhTXunlOXRbSrfu8Wayrivoks5rAcGIgaJpZM4Kxim_
.

Wojtek Mach

@wojtekmach
Copy link
Member

@josevalim that was it, thanks! Btw, is it expected that iex shows c: prefix as on screenshot below?

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,

zrzut ekranu 2016-11-21 o 17 27 46

or maybe IEx should be taught to parse this and leave it out?

@josevalim
Copy link
Member

I would leave it in because otherwise you may try to do h Ecto.Repo.insert_all/3 and it won't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants