Skip to main content

Module context

Module context 

Source
Expand description

ModeContext: the handle passed to crate::Mode::on_activate.

Owned (Send + 'static) so the dispatcher can hand it to a tokio::spawned future without lifetime gymnastics. Hooks that need to mutate options (e.g. lsp-folding-mode swapping foldmethod=lsp on activate) reach the typed-options registry through ModeContext::config. Hooks that need to publish typed events use ModeContext::events. Hooks that need a subsystem handle (LSP supervisor, BufferStore) call ModeContext::service.

Why no BufferLocals access:

Mode-private state is owned by the Mode::Guard returned from on_activate. The Guard’s Drop impl performs cleanup. App-managed buffer-locals (icons, syntax handles, folds, …) live in an App-owned map and are written through App-side code paths, not through ctx.

Why owned handles (not &Arc<T>):

The context is constructed once per activation and moved into the lifecycle future. The future captures it across await points, so every field must be owned and Send + 'static. Arc<T> is cheap to clone – the dispatcher does one Arc::clone per activation when building the context.

Structs§

ModeContext
Lifecycle context. Carries the current activation’s metadata + cheap-clone handles to the system registries the mode may need.