Skip to content

Commit 0a42d7a

Browse files
committed
IEX's s helper should include callbacks in its output
1 parent 31dcbfb commit 0a42d7a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ defmodule IEx.Helpers do
344344

345345
@doc false
346346
def s(module, function) when is_atom(function) do
347-
specs = lc {{f, _arity}, _spec} = spec inlist Kernel.Typespec.beam_specs(module),
347+
specs = lc {{f, _arity}, _spec} = spec inlist beam_specs(module),
348348
f == function do
349349
print_spec(spec)
350350
spec
@@ -358,7 +358,7 @@ defmodule IEx.Helpers do
358358
end
359359

360360
def s(module, []) do
361-
specs = lc spec inlist Kernel.Typespec.beam_specs(module), do: print_spec(spec)
361+
specs = lc spec inlist beam_specs(module), do: print_spec(spec)
362362

363363
if specs == [] do
364364
IO.puts "No specs for #{inspect module} have been found"
@@ -369,7 +369,7 @@ defmodule IEx.Helpers do
369369

370370
@doc false
371371
def s(module, function, arity) do
372-
spec = List.keyfind(Kernel.Typespec.beam_specs(module), { function, arity }, 0)
372+
spec = List.keyfind(beam_specs(module), { function, arity }, 0)
373373

374374
if spec do
375375
print_spec(spec)
@@ -380,16 +380,22 @@ defmodule IEx.Helpers do
380380
:ok
381381
end
382382

383+
defp beam_specs(module) do
384+
specs = Enum.map(Kernel.Typespec.beam_specs(module), {:spec, &1})
385+
callbacks = Enum.map(Kernel.Typespec.beam_callbacks(module), {:callback, &1})
386+
List.concat(specs, callbacks)
387+
end
388+
383389
defp print_type({ kind, type }) do
384390
ast = Kernel.Typespec.type_to_ast(type)
385391
IO.puts "@#{kind} #{Macro.to_binary(ast)}"
386392
true
387393
end
388394

389-
defp print_spec({ { name, _arity }, specs }) do
395+
defp print_spec({kind, { { name, _arity }, specs }}) do
390396
Enum.each specs, fn(spec) ->
391397
binary = Macro.to_binary Kernel.Typespec.spec_to_ast(name, spec)
392-
IO.puts "@spec #{binary}"
398+
IO.puts "@#{kind} #{binary}"
393399
end
394400
true
395401
end

0 commit comments

Comments
 (0)