mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-11 01:18:12 +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
|
:protocol | :implementation | :exception | :struct | :behaviour | nil
|
||||||
def get_module_subtype(module) do
|
def get_module_subtype(module) do
|
||||||
cond do
|
cond do
|
||||||
module_has_function?(module, :__protocol__, 1) ->
|
not ensure_loaded?(module) ->
|
||||||
|
nil
|
||||||
|
|
||||||
|
function_exported?(module, :__protocol__, 1) ->
|
||||||
:protocol
|
:protocol
|
||||||
|
|
||||||
module_has_function?(module, :__impl__, 1) ->
|
function_exported?(module, :__impl__, 1) ->
|
||||||
:implementation
|
:implementation
|
||||||
|
|
||||||
module_has_function?(module, :__struct__, 0) ->
|
function_exported?(module, :__struct__, 0) ->
|
||||||
if module_has_function?(module, :exception, 1) do
|
if function_exported?(module, :exception, 1) do
|
||||||
:exception
|
:exception
|
||||||
else
|
else
|
||||||
:struct
|
:struct
|
||||||
end
|
end
|
||||||
|
|
||||||
module_has_function?(module, :behaviour_info, 1) ->
|
function_exported?(module, :behaviour_info, 1) ->
|
||||||
:behaviour
|
:behaviour
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
@ -128,7 +131,9 @@ defmodule Livebook.Intellisense.Docs do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp module_has_function?(module, func, arity) do
|
# In case insensitive file systems, attempting to load
|
||||||
Code.ensure_loaded?(module) and function_exported?(module, func, arity)
|
# Elixir will log a warning in the terminal as it wrongly
|
||||||
end
|
# loads elixir.beam, so we explicitly list it.
|
||||||
|
defp ensure_loaded?(Elixir), do: false
|
||||||
|
defp ensure_loaded?(module), do: Code.ensure_loaded?(module)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue