livebook/test/support/single_evaluator_runtime.ex
Jonatan Kłosko 700987dc02
Add editor completion to Elixir cells (#208)
* Implement editor completion for Elixir cells

* Add completion tests

* Refactor completion

* Only extract Markdown docs for now

* Fix Elixir version-dependent test

* Fix docs matching

* Use upcoming Code.cursor_context/2

* Start temporary completion processes under a supervisor

* Show Erlang docs in completion items

* Update to latest Code.cursor_context

* Refactor completion

* Fix module completion when alias expands to Erlang module

* Remove tests-generated notebook

* Show variables and map fields differently

* Adjust signatures formatting
2021-04-20 19:34:17 +02:00

63 lines
1.4 KiB
Elixir

defmodule LivebookTest.Runtime.SingleEvaluator do
@moduledoc false
# A simple runtime backed by a single evaluator process
# running on the local node.
#
# This allows for working code evaluation without
# starting a standalone Elixir runtime, so is neat for testing.
defstruct [:evaluator]
def init() do
with {:ok, evaluator} <- Livebook.Evaluator.start_link() do
{:ok, %__MODULE__{evaluator: evaluator}}
end
end
end
defimpl Livebook.Runtime, for: LivebookTest.Runtime.SingleEvaluator do
alias Livebook.Evaluator
def connect(runtime) do
Process.monitor(runtime.evaluator)
end
def disconnect(_runtime), do: :ok
def evaluate_code(
runtime,
code,
_container_ref,
evaluation_ref,
prev_evaluation_ref,
opts \\ []
) do
Evaluator.evaluate_code(
runtime.evaluator,
self(),
code,
evaluation_ref,
prev_evaluation_ref,
opts
)
:ok
end
def forget_evaluation(runtime, _container_ref, evaluation_ref) do
Evaluator.forget_evaluation(runtime.evaluator, evaluation_ref)
end
def drop_container(_runtime, _container_ref), do: :ok
def request_completion_items(runtime, send_to, ref, hint, _container_ref, evaluation_ref) do
Evaluator.request_completion_items(
runtime.evaluator,
send_to,
ref,
hint,
evaluation_ref
)
end
end