diff --git a/apps/language_server/lib/language_server/dialyzer.ex b/apps/language_server/lib/language_server/dialyzer.ex index fc27d61b5..a70b3fb2d 100644 --- a/apps/language_server/lib/language_server/dialyzer.ex +++ b/apps/language_server/lib/language_server/dialyzer.ex @@ -359,7 +359,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do files_to_analyze = for module <- modules_to_analyze do - temp_modules[module] || :code.which(module) + temp_modules[module] || Utils.get_beam_file(module) end # Clear warnings for files that changed or need to be re-analyzed diff --git a/apps/language_server/lib/language_server/dialyzer/manifest.ex b/apps/language_server/lib/language_server/dialyzer/manifest.ex index 5d3064550..ade007961 100644 --- a/apps/language_server/lib/language_server/dialyzer/manifest.ex +++ b/apps/language_server/lib/language_server/dialyzer/manifest.ex @@ -1,5 +1,5 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Manifest do - alias ElixirLS.LanguageServer.{Dialyzer, JsonRpc} + alias ElixirLS.LanguageServer.{Dialyzer, Dialyzer.Utils, JsonRpc} import Record import Dialyzer.Utils @@ -125,7 +125,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Manifest do |> Path.wildcard() |> Enum.map(&pathname_to_module/1) |> expand_references() - |> Enum.map(&:code.which/1) + |> Enum.map(&Utils.get_beam_file/1) |> Enum.filter(&is_list/1) File.mkdir_p!(Path.dirname(elixir_plt_path())) diff --git a/apps/language_server/lib/language_server/dialyzer/utils.ex b/apps/language_server/lib/language_server/dialyzer/utils.ex index ffb7f6ec1..3e88985f0 100644 --- a/apps/language_server/lib/language_server/dialyzer/utils.ex +++ b/apps/language_server/lib/language_server/dialyzer/utils.ex @@ -1,11 +1,26 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Utils do @epoch_gregorian_seconds 62_167_219_200 + @spec dialyzable?(module()) :: boolean() def dialyzable?(module) do - file = :code.which(module) + file = get_beam_file(module) is_list(file) and match?({:ok, _}, :dialyzer_utils.get_core_from_beam(file)) end + @spec get_beam_file(module()) :: charlist() | :preloaded | :non_existing | :cover_compiled + def get_beam_file(module) do + case :code.which(module) do + file when is_list(file) -> + file + + other -> + case :code.get_object_code(module) do + {_module, _binary, beam_filename} -> beam_filename + :error -> other + end + end + end + def pathname_to_module(path) do String.to_atom(Path.basename(path, ".beam")) end