Skip to content

Commit af81311

Browse files
committed
prefer metadata as it is faster
1 parent 590435f commit af81311

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

lib/elixir_sense/core/introspection.ex

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -641,44 +641,35 @@ defmodule ElixirSense.Core.Introspection do
641641
defp find_metadata_function({nil, fun}, current_module, imports, mods_funs) do
642642
mods = [current_module | imports]
643643

644-
case mods
645-
|> Enum.find(fn mod ->
646-
find_metadata_function({mod, fun}, current_module, imports, mods_funs) != {nil, nil}
647-
end) do
644+
case Enum.find(mods, fn mod ->
645+
find_metadata_function({mod, fun}, current_module, imports, mods_funs) != {nil, nil}
646+
end) do
648647
nil -> {nil, nil}
649648
mod -> {mod, fun}
650649
end
651650
end
652651

653652
defp find_metadata_function({mod, nil}, _current_module, _imports, mods_funs) do
654-
case Code.ensure_loaded(mod) do
655-
{:module, _} ->
656-
{mod, nil}
657-
658-
_ ->
659-
case mods_funs[mod] do
660-
nil -> {nil, nil}
661-
_ -> {mod, nil}
662-
end
653+
if Map.has_key?(mods_funs, mod) or match?({:module, _}, Code.ensure_loaded(mod)) do
654+
{mod, nil}
655+
else
656+
{nil, nil}
663657
end
664658
end
665659

666660
defp find_metadata_function({mod, fun}, _current_module, _imports, mods_funs) do
667-
if ModuleInfo.has_function?(mod, fun) or has_type?(mod, fun) do
661+
# TODO types from metadata
662+
found_in_metadata = case mods_funs[mod] do
663+
nil ->
664+
false
665+
funs ->
666+
Enum.any?(funs, fn {{f, _a}, _} -> f == fun end)
667+
end
668+
669+
if found_in_metadata or ModuleInfo.has_function?(mod, fun) or has_type?(mod, fun) do
668670
{mod, fun}
669671
else
670-
# TODO types from metadata
671-
case mods_funs[mod] do
672-
nil ->
673-
{nil, nil}
674-
675-
funs ->
676-
if funs |> Enum.any?(fn {{f, _a}, _} -> f == fun end) do
677-
{mod, fun}
678-
else
679-
{nil, nil}
680-
end
681-
end
672+
{nil, nil}
682673
end
683674
end
684675

0 commit comments

Comments
 (0)