Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly get beam file for preloaded modules in dialyzer #218

Merged
merged 1 commit into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/language_server/lib/language_server/dialyzer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/language_server/lib/language_server/dialyzer/manifest.ex
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()))
Expand Down
17 changes: 16 additions & 1 deletion apps/language_server/lib/language_server/dialyzer/utils.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down