From 3e531b92524c88b90a1fb2bec5f3e5dd9807af15 Mon Sep 17 00:00:00 2001 From: Fenix Date: Fri, 11 Feb 2022 19:11:06 +0800 Subject: [PATCH] Fix hover bug (#674) * #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 --- .../lib/language_server/providers/hover.ex | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/language_server/lib/language_server/providers/hover.ex b/apps/language_server/lib/language_server/providers/hover.ex index 53d295aad..1c61e8ab1 100644 --- a/apps/language_server/lib/language_server/providers/hover.ex +++ b/apps/language_server/lib/language_server/providers/hover.ex @@ -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 @@ -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)