livebook/lib/livebook_web/live/session_live/embedded_live.ex
Jonatan Kłosko e2490c0f7f
Implement signature intellisense (#640)
* Remove Code.Fragment backport

* Fix tests compatibility with Elixir 1.13

* Implement signature intellisense

* Don't show signatures on module attributes

* Add tests for calls with do-end block

* Unify spec formatting

* Insert parentheses when completing a function call

* Send all text until cursor in signature request

* Add configuration for completion/signature popups (#693)

* Add editor settings form

* Add configuration for intellisense defaults

* Read fresh settings when editor mounts

* Scope attribute names

* Fix disabled button styling

* Simplify signature box and enable by default

* Split settings into system and user sections

* Update lib/livebook_web/live/settings_live.ex

Co-authored-by: José Valim <jose.valim@dashbit.co>

* Update lib/livebook_web/live/settings_live.ex

Co-authored-by: José Valim <jose.valim@dashbit.co>

Co-authored-by: José Valim <jose.valim@dashbit.co>

* Fix spacing in documentation tests

Co-authored-by: José Valim <jose.valim@dashbit.co>
2021-12-03 21:57:21 +01:00

55 lines
1.8 KiB
Elixir

defmodule LivebookWeb.SessionLive.EmbeddedLive do
use LivebookWeb, :live_view
alias Livebook.{Session, Runtime}
@impl true
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
if connected?(socket) do
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
end
{:ok, assign(socket, session: session, current_runtime: current_runtime)}
end
@impl true
def render(assigns) do
~H"""
<div class="flex-col space-y-5">
<p class="text-gray-700">
Run the notebook code within the Livebook node itself.
This is reserved for specific cases where there is no option
of starting a separate Elixir runtime (for example, on embedded
devices or cases where the amount of memory available is
limited). Prefer the "Elixir standalone" runtime whenever possible.
</p>
<p class="text-gray-700">
<span class="font-semibold">Warning:</span>
any module that you define will be defined globally until
you restart Livebook. Furthermore, code in one notebook
may interfere with code from another notebook.
</p>
<button class="button-base button-blue" phx-click="init">
<%= if(matching_runtime?(@current_runtime), do: "Reconnect", else: "Connect") %>
</button>
</div>
"""
end
defp matching_runtime?(%Runtime.Embedded{}), do: true
defp matching_runtime?(_runtime), do: false
@impl true
def handle_event("init", _params, socket) do
{:ok, runtime} = Runtime.Embedded.init()
Session.connect_runtime(socket.assigns.session.pid, runtime)
{:noreply, socket}
end
@impl true
def handle_info({:operation, {:set_runtime, _pid, runtime}}, socket) do
{:noreply, assign(socket, current_runtime: runtime)}
end
def handle_info(_message, socket), do: {:noreply, socket}
end