Skip to content

Commit ea19aa4

Browse files
committed
address todo
1 parent fd38132 commit ea19aa4

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

lib/elixir_sense/core/introspection.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ defmodule ElixirSense.Core.Introspection do
184184

185185
defp get_spec_from_typespec(mod, fun) do
186186
# TypeInfo.get_function_specs does fallback to behaviours
187-
{behaviour, specs} = TypeInfo.get_function_specs(mod, fun, :any)
187+
function_specs = TypeInfo.get_function_specs(mod, fun, :any)
188188

189189
results =
190-
for {{_name, _arity}, [params | _]} = spec <- specs do
190+
for {behaviour, specs} <- function_specs, {{_name, _arity}, [params | _]} = spec <- specs do
191191
params = TypeInfo.extract_params(params)
192192

193193
%{

lib/elixir_sense/core/options.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,16 @@ defmodule ElixirSense.Core.Options do
135135
{:macro, :"MACRO-#{function}", arity + 1, parameter_position_range}
136136
end
137137

138-
{_behaviour, specs} =
138+
function_specs =
139139
ElixirSense.Core.TypeInfo.get_function_specs(
140140
module,
141141
modified_function,
142142
modified_arity
143143
)
144144

145-
for {_, spec_entries} <- specs, spec <- spec_entries do
145+
for {_behaviour, specs} <- function_specs,
146+
{_, spec_entries} <- specs,
147+
spec <- spec_entries do
146148
spec = maybe_unpack_caller(spec, kind)
147149

148150
NormalizedTypespec.spec_to_quoted(function, spec)

lib/elixir_sense/core/type_info.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,12 @@ defmodule ElixirSense.Core.TypeInfo do
316316
end
317317

318318
if function_specs != [] do
319-
{nil, function_specs}
319+
[{nil, function_specs}]
320320
else
321-
# TODO this will not work correctly for :any arity in case many functions with the same name and different arities
322-
# are implement different behaviours
323321
callback_specs =
324322
module
325323
|> Behaviours.get_module_behaviours()
326-
|> Enum.reduce_while(nil, fn behaviour, acc ->
324+
|> Enum.reduce_while([], fn behaviour, acc ->
327325
behaviour_specs = behaviour |> get_module_callbacks()
328326

329327
callback_specs =
@@ -334,7 +332,11 @@ defmodule ElixirSense.Core.TypeInfo do
334332
end
335333

336334
if callback_specs != [] do
337-
{:halt, {behaviour, callback_specs}}
335+
if arity == :any do
336+
{:halt, [{behaviour, callback_specs}]}
337+
else
338+
{:cont, [{behaviour, callback_specs} | acc]}
339+
end
338340
else
339341
{:cont, acc}
340342
end
@@ -343,7 +345,7 @@ defmodule ElixirSense.Core.TypeInfo do
343345
if callback_specs do
344346
callback_specs
345347
else
346-
{nil, []}
348+
[{nil, []}]
347349
end
348350
end
349351
end

lib/elixir_sense/providers/hover/docs.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,18 @@ defmodule ElixirSense.Providers.Hover.Docs do
495495

496496
defp get_func_docs_from_typespec(mod, fun, call_arity) do
497497
# TypeInfo.get_function_specs does fallback to behaviours
498-
{behaviour, specs} = TypeInfo.get_function_specs(mod, fun, call_arity)
498+
function_specs = TypeInfo.get_function_specs(mod, fun, call_arity)
499499
app = ElixirSense.Core.Applications.get_application(mod)
500500

501-
meta =
502-
if behaviour do
503-
%{implementing: behaviour}
504-
else
505-
%{}
506-
end
507-
508501
results =
509-
for {{_name, arity}, [params | _]} <- specs do
502+
for {behaviour, specs} <- function_specs, {{_name, arity}, [params | _]} <- specs do
503+
meta =
504+
if behaviour do
505+
%{implementing: behaviour}
506+
else
507+
%{}
508+
end
509+
510510
fun_args_text = TypeInfo.extract_params(params)
511511

512512
%{

0 commit comments

Comments
 (0)