Skip to content

Commit

Permalink
Fix hover bug (#674)
Browse files Browse the repository at this point in the history
* #673 fix hover bug for

* use function_exported to check module be loaded

Change-Id: I8e3c3cde067a7d3313422c0a94f4c4a464bd37de

* remove rescue and use if instead of nested cond

Change-Id: Ia85056971d7333df5d6a7cf6d3a6bd21c87635eb

Co-authored-by: zhuzhenfeng.code <[email protected]>
  • Loading branch information
gofenix and zhuzhenfeng.code authored Feb 11, 2022
1 parent 8e92bdc commit 3e531b9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/language_server/lib/language_server/providers/hover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
end

defp dep_name(root_mod_name, project_dir) do
s = root_mod_name |> source()

cond do
third_dep?(s, project_dir) -> third_dep_name(s, project_dir)
builtin?(s) -> builtin_dep_name(s)
true -> ""
if not elixir_mod_exported?(root_mod_name) do
""
else
s = root_mod_name |> source()
cond do
third_dep?(s, project_dir) -> third_dep_name(s, project_dir)
builtin?(s) -> builtin_dep_name(s)
true -> ""
end
end
end

Expand All @@ -149,6 +152,10 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
dep.__info__(:compile) |> Keyword.get(:source) |> List.to_string()
end

defp elixir_mod_exported?(mod_name) do
("Elixir." <> mod_name) |> String.to_atom() |> function_exported?(:__info__, 1)
end

defp third_dep?(source, project_dir) do
prefix = project_dir <> "/deps"
String.starts_with?(source, prefix)
Expand Down

0 comments on commit 3e531b9

Please sign in to comment.