Packages
livebook
0.18.4
0.19.8
0.19.7
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.6
0.18.5
0.18.4
0.18.3
0.18.2
0.18.1
0.18.0
0.17.3
0.17.2
0.17.1
0.17.0
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.5
0.15.4
0.15.3
0.15.2
0.15.1
0.15.0
0.14.7
0.14.6
0.14.5
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.14.0-rc.1
0.14.0-rc.0
0.13.3
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.3
0.2.2
0.2.1
0.2.0
0.1.2
0.1.1
0.1.0
Automate code & data workflows with interactive notebooks
Current section
Files
Jump to
Current section
Files
lib/livebook/intellisense.ex
defmodule Livebook.Intellisense do
# Language-specific intellisense that is used by the code editor.
#
# This module defines a behaviour and dispatches the intellisense
# implementation to the appropriate language-specific module.
alias Livebook.Intellisense
alias Livebook.Runtime
@typedoc """
Evaluation state to consider for intellisense.
The `:map_binding` is only called when a value needs to be extracted
from binding.
"""
@type context :: %{
env: Macro.Env.t(),
ebin_path: String.t() | nil,
map_binding: (Code.binding() -> any())
}
@doc """
Language-specific implementation of `t:Runtime.intellisense_request/1`.
"""
@callback handle_request(
request :: Runtime.intellisense_request(),
context :: context(),
node :: node()
) :: Runtime.intellisense_response()
@doc """
Resolves an intellisense request as defined in
`t:Runtime.intellisense_request/1`.
"""
@spec handle_request(
Runtime.language(),
Runtime.intellisense_request(),
context(),
node()
) :: Runtime.intellisense_response()
def handle_request(language, request, context, node) do
if impl = impl_for_language(language) do
apply(impl, :handle_request, [request, context, node])
end
end
defp impl_for_language(:elixir), do: Intellisense.Elixir
defp impl_for_language(:erlang), do: Intellisense.Erlang
defp impl_for_language(_other), do: nil
@doc """
Adjusts the system for more accurate intellisense.
"""
@spec load() :: :ok
def load() do
# Completion looks for modules in loaded applications, so we ensure
# that the most relevant built-in applications are loaded
apps = [:erts, :crypto, :inets, :public_key, :runtime_tools, :ex_unit, :iex]
for app <- apps do
Application.load(app)
end
:ok
end
@doc """
Clears all cache stored by the intellisense modules.
"""
@spec clear_cache() :: :ok
def clear_cache() do
for node <- Node.list() do
clear_cache(node)
end
:ok
end
@doc """
Clear any cache stored related to the given node.
"""
@spec clear_cache(node()) :: :ok
def clear_cache(node) do
Intellisense.Elixir.IdentifierMatcher.clear_all_loaded(node)
end
end