Skip to main content

spawn_autoread_watcher_task

Function spawn_autoread_watcher_task 

Source
pub fn spawn_autoread_watcher_task(
    wake: Arc<Notify>,
) -> Result<(AutoreadWatcherHandle, UnboundedReceiver<AutoreadChange>), Error>
Expand description

Spawn the autoread watcher task on the LSP runtime. Returns the handle Editor keeps plus the change receiver the host drains (AR.4). Err only if notify itself fails to construct the OS watcher.

wake is the editor’s async_landed notifier. It is a required parameter, not an option: the change channel is drained by run_tick_pending, which in production runs on the next keystroke or on an async_landed wake. Without the wake an external change (a git checkout from magit, a git pull in another terminal) sits in the channel until the user happens to press a key. Threading it through lattice_mode::inbound::make_inbound_raw bakes the wake into every send, so it cannot be forgotten (paramount goal #4 — async-correct by construction, not by discipline).

make_inbound_raw rather than make_inbound because the per-item work is irreducibly &mut Editor (the reload rewrites buffer contents, cursor and scroll), which a FnMut(T) -> Vec<Effect> handler cannot capture — the case that constructor documents.