Skip to main content

Module tick_callback

Module tick_callback 

Source
Expand description

IDE-protocol I1.1: tick-callback registry — the one generic host primitive the Claude Code IDE peer needs.

A mode registers a per-tick drain closure; the host runs every registered closure once per editor tick (inside run_tick_pending) and applies the Effects they return through the existing effect pipeline. This generalizes the host’s existing hardcoded per-tick drains (option_change_rx, lsp_log_event_rx, …) — those are the smell this primitive replaces for new subsystems: rather than adding an Editor::drain_<x> method + an Option<Receiver> field per subsystem, a mode owns its channel and registers a closure that drains it.

Per feedback_mode_owns_its_surface: the drain body lives in the mode’s owning crate (it closes over the mode’s own receiver), not in lattice-host. The host’s role is the generic run-loop + the effect-apply pipeline.

§Shape

Unlike ActionHandlerRegistry — whose Fn handlers are wait-free behind arc-swap — a tick callback is FnMut: it mutates captured state (a channel receiver) on every run. So the registry stores the closures behind a Mutex<Vec<…>> rather than an ArcSwap. Registration is rare (per mode activation / deactivation); run_all is the per-tick hot path, but it runs on the editor (actor) thread only — the lock is uncontended in practice.

§Lifecycle

register returns a TickCallbackRegistration RAII token. A mode’s Guard carries the token; dropping the Guard on deactivation drops the token, which removes the closure — so a stopped mode contributes no per-tick work.

Structs§

TickCallbackRegistration
RAII registration token. Dropping it removes the callback. Modes aggregate the token into their Mode::Guard; when the Guard drops on deactivation, the callback is removed and the mode contributes no further per-tick work.
TickCallbackRegistry
Registry of mode-contributed per-tick drain closures.

Type Aliases§

TickCallback
A per-tick drain closure. Returns the Effects the host should apply this tick (empty when there was nothing pending). FnMut because the canonical body drains a channel receiver, which needs &mut.
TickCallbackRegistryHandle
Typed handle for ServiceRegistry lookup. Boot registers a fresh TickCallbackRegistry under this alias; modes pull it from on_activate via ctx.service::<TickCallbackRegistryHandle>() (or receive it directly at registration) and add their drain.