@@ -55,6 +55,8 @@ defmodule IEx.Introspection do
55
55
case h_mod_fun ( module , function ) do
56
56
:ok ->
57
57
:ok
58
+ :behaviour_found ->
59
+ behaviour_found ( "#{ inspect module } .#{ function } " )
58
60
:no_docs ->
59
61
puts_error ( "#{ inspect module } was not compiled with docs" )
60
62
:not_found ->
@@ -70,7 +72,14 @@ defmodule IEx.Introspection do
70
72
h ( mod , fun , arity )
71
73
end
72
74
73
- if result != [ ] , do: :ok , else: :not_found
75
+ cond do
76
+ result != [ ] ->
77
+ :ok
78
+ has_callback? ( mod , fun ) ->
79
+ :behaviour_found
80
+ true ->
81
+ :not_found
82
+ end
74
83
else
75
84
:no_docs
76
85
end
@@ -95,6 +104,8 @@ defmodule IEx.Introspection do
95
104
case h_mod_fun_arity ( module , function , arity ) do
96
105
:ok ->
97
106
:ok
107
+ :behaviour_found ->
108
+ behaviour_found ( "#{ inspect module } .#{ function } /#{ arity } " )
98
109
:no_docs ->
99
110
puts_error ( "#{ inspect module } was not compiled with docs" )
100
111
:not_found ->
@@ -115,13 +126,37 @@ defmodule IEx.Introspection do
115
126
end
116
127
:ok
117
128
else
118
- :not_found
129
+ if has_callback? ( mod , fun , arity ) do
130
+ :behaviour_found
131
+ else
132
+ :not_found
133
+ end
119
134
end
120
135
else
121
136
:no_docs
122
137
end
123
138
end
124
139
140
+ defp has_callback? ( mod , fun ) do
141
+ mod
142
+ |> Code . get_docs ( :callback_docs )
143
+ |> find_callback_doc ( fun )
144
+ end
145
+
146
+ defp has_callback? ( mod , fun , arity ) do
147
+ mod
148
+ |> Code . get_docs ( :callback_docs )
149
+ |> find_callback_doc ( fun , arity )
150
+ end
151
+
152
+ defp find_callback_doc ( docs , fun ) do
153
+ Enum . any? ( docs , & match? ( { { ^ fun , _ } , _ , _ , _ } , & 1 ) )
154
+ end
155
+
156
+ defp find_callback_doc ( docs , fun , arity ) do
157
+ Enum . any? ( docs , & match? ( { { ^ fun , ^ arity } , _ , _ , _ } , & 1 ) )
158
+ end
159
+
125
160
defp find_doc ( docs , fun , arity ) do
126
161
doc = List . keyfind ( docs , { fun , arity } , 0 ) || find_doc_defaults ( docs , fun , arity )
127
162
if doc != nil and has_content? ( doc ) , do: doc
@@ -440,7 +475,14 @@ defmodule IEx.Introspection do
440
475
441
476
defp no_specs ( for ) , do: no ( for , "specification" )
442
477
defp no_types ( for ) , do: no ( for , "type information" )
443
- defp no_docs ( for ) , do: no ( for , "documentation" )
478
+ defp no_docs ( for ) , do: no ( for , "documentation" )
479
+
480
+ defp behaviour_found ( for ) do
481
+ puts_error ( """
482
+ No documentation for function #{ for } was found, but there is a callback with the same name.
483
+ You can view callback documentations with the b/1 helper.
484
+ """ )
485
+ end
444
486
445
487
defp no ( for , type ) do
446
488
puts_error ( "No #{ type } for #{ for } was found" )
0 commit comments