mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-10 17:15:09 +08:00
Do not try to accidentally load elixir.beam (#739)
This commit is contained in:
parent
64fce545d3
commit
18d8eccc9e
1 changed files with 13 additions and 8 deletions
|
@ -107,20 +107,23 @@ defmodule Livebook.Intellisense.Docs do
|
|||
:protocol | :implementation | :exception | :struct | :behaviour | nil
|
||||
def get_module_subtype(module) do
|
||||
cond do
|
||||
module_has_function?(module, :__protocol__, 1) ->
|
||||
not ensure_loaded?(module) ->
|
||||
nil
|
||||
|
||||
function_exported?(module, :__protocol__, 1) ->
|
||||
:protocol
|
||||
|
||||
module_has_function?(module, :__impl__, 1) ->
|
||||
function_exported?(module, :__impl__, 1) ->
|
||||
:implementation
|
||||
|
||||
module_has_function?(module, :__struct__, 0) ->
|
||||
if module_has_function?(module, :exception, 1) do
|
||||
function_exported?(module, :__struct__, 0) ->
|
||||
if function_exported?(module, :exception, 1) do
|
||||
:exception
|
||||
else
|
||||
:struct
|
||||
end
|
||||
|
||||
module_has_function?(module, :behaviour_info, 1) ->
|
||||
function_exported?(module, :behaviour_info, 1) ->
|
||||
:behaviour
|
||||
|
||||
true ->
|
||||
|
@ -128,7 +131,9 @@ defmodule Livebook.Intellisense.Docs do
|
|||
end
|
||||
end
|
||||
|
||||
defp module_has_function?(module, func, arity) do
|
||||
Code.ensure_loaded?(module) and function_exported?(module, func, arity)
|
||||
end
|
||||
# In case insensitive file systems, attempting to load
|
||||
# Elixir will log a warning in the terminal as it wrongly
|
||||
# loads elixir.beam, so we explicitly list it.
|
||||
defp ensure_loaded?(Elixir), do: false
|
||||
defp ensure_loaded?(module), do: Code.ensure_loaded?(module)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue