Skip to main content

Module editor_actor

Module editor_actor 

Source
Expand description

EditorActor — the editor runs on its own thread.

Phase 5.8.AF.5 / Slice 3c.0.

§Why this exists

Paramount goal #4 (CLAUDE.md): “Three-layer architecture (UI / Core / Plugins) communicating via typed message passing. Multi-threaded by construction. Nothing blocks the UI – enforced architecturally, not by discipline.”

After Slices 3a + 3b.* moved every per-buffer LSP cache off the renderer thread via wait-free read primitives, the last piece of architectural debt is Editor itself living on the renderer thread. While the renderer holds &mut Editor, the UI thread can (in principle) do editor work synchronously, and any future feature that does so silently regresses the architecture. The fix: relocate Editor to its own thread so the renderer is physically incapable of touching it directly.

§Shape

  • EditorActorHandle — what the renderer holds. Carries the command-send half (cmd_tx), the signal-receive half (signal_rx), and a clone of the editor’s Arc<ArcSwap<RenderState>>. Not Clone because it owns the unique receiver; send_action / send_command go through &self.
  • EditorCommand — the typed mailbox payload. Renderer-to- editor messages. Includes Apply(Action), HandleEffect, DispatchBlocking { invocation, reply }, Tick, Ping, Shutdown. Extensible: subsequent slices add variants.
  • spawn_editor_actor(editor) -> EditorActorHandle — takes ownership of an Editor, spawns a dedicated thread with a current_thread tokio runtime, returns the handle. The thread name is "lattice-editor" for observability.

§Slice 3c.0 status

Everything in this module is dormant – no production call site wires spawn_editor_actor yet. The follow-on sub-slices:

  • 3c.1: populate ActiveDocumentRenderState (the read contract for cursor/scroll/modal/etc.) so renderers can migrate off direct editor.X reads.
  • 3c.2 / 3c.3: TUI / GPUI renderers switch their reads to RenderState.
  • 3c.4: renderers wire EditorActorHandle; App::apply becomes handle.send_action(action).
  • 3c.5: sever Arc<Editor> from renderer entirely.
  • 3c.6 / 3c.7: polish + docs.

Tests in this file verify the substrate works end-to-end: spawn the actor, send a Ping, await the reply.

Structs§

ActorGone
Error returned by the synchronous handle methods when the actor thread has shut down. Production code maps this to a fatal condition: the editor thread dying is unrecoverable. In tests, surfaces as a panic! via unwrap (acceptable — test fixtures keep the handle alive for their duration).
EditorActorHandle
Renderer-side handle to the editor actor.

Enums§

EditorCommand
Renderer-to-editor mailbox payload. Each variant corresponds to a way the renderer (or another task) drives the editor’s state.

Functions§

spawn_editor_actor
Spawn the editor actor on a dedicated thread with a current_thread tokio runtime. Takes ownership of editor.