@@ -236,14 +236,7 @@ defmodule ExDoc.Retriever do
236236 function = actual_def ( name , arity , type )
237237 line = find_actual_line ( module_info . abst_code , function , :function ) || doc_line
238238
239- behaviour = Map . get ( module_info . impls , { name , arity } )
240-
241- doc =
242- if is_nil ( doc ) && behaviour do
243- "Callback implementation for `c:#{ inspect behaviour } .#{ name } /#{ arity } `."
244- else
245- doc
246- end
239+ doc = docstring ( doc , name , arity , Map . fetch ( module_info . impls , { name , arity } ) )
247240
248241 specs = module_info . specs
249242 |> Map . get ( function , [ ] )
@@ -272,6 +265,22 @@ defmodule ExDoc.Retriever do
272265 end
273266 end
274267
268+ defp docstring ( nil , name , arity , { :ok , behaviour } ) do
269+ callback_docs = Code . get_docs ( behaviour , :callback_docs ) || [ ]
270+ case List . keyfind ( callback_docs , { name , arity } , 0 ) do
271+ { { ^ name , ^ arity } , _ , :callback , callback_docs } when is_binary ( callback_docs ) ->
272+ [ header , body ] = String . split ( callback_docs , "\n " , parts: 2 )
273+ info = "Documentation for callback `c:#{ inspect behaviour } .#{ name } /#{ arity } `."
274+ "#{ header } \n \n #{ info } \n \n #{ String . trim_leading ( body ) } "
275+ _ ->
276+ "Callback implementation for `c:#{ inspect behaviour } .#{ name } /#{ arity } `."
277+ end
278+ end
279+
280+ defp docstring ( doc , _name , _arity , _behaviour ) do
281+ doc
282+ end
283+
275284 defp get_callbacks ( % { type: :behaviour , name: name , abst_code: abst_code } , source ) do
276285 optional_callbacks = get_optional_callbacks ( abst_code )
277286 ( Code . get_docs ( name , :callback_docs ) || [ ] )
0 commit comments