Expand description
The event/hook guest world (PH7.8b).
An event-observing plugin implements the events-plugin world: it imports
the events subscription API (host-provided) and host-services, and
exports register-events (the host calls it once to drive subscription
registration) and on-event (host→guest delivery). This module holds the
fifth bindgen! (after plugin, picker-source-plugin,
completion-source-plugin, grammar-plugin) for that world — the
shared-types trick (with: points
types + host-services at the plugin world’s generated modules so a
crossed event value is the SAME Rust type WitBoundary round-trips,
boundary_event.rs; PH7.3d precedent).
Async (unlike grammar). Event delivery is OFF the keystroke path: the host
owns an mpsc and pushes each event to on-event on the plugin’s own task
(§5.10.4). So the bindgen! sets exports: { default: async } — an on-event
call suspends the guest stack, never pins the caller’s thread, and a slow
handler can never freeze a keystroke or another subscriber (paramount #4). The
per-plugin actor that drains the bus channel and drives on-event is the
event_task bridge (PH7.8c).
Registration flow (the grammar register-grammar precedent): the host calls
the guest’s register-events export; the guest calls the imported
events.subscribe(filter, handler) host function; that records the
declaration into the Store’s EventContributions (via the events::Host
impl on PluginState, lib.rs); after the export returns, the host drains the
subscriptions and wires each to the native EventBus (PH7.8c).
Structs§
- Event
Contributions - The per-plugin accumulator the
events::Hostimpl records into duringregister-events(lib.rs). Held inPluginState; drained by the host after the registration export returns (PH7.8c).recordis the sync host-func body (it only pushes — it cannot trap), factored here (theGrammarContributionsprecedent) so recording is unit-testable without aPluginState/ guest. - Recorded
Subscription - One subscription a plugin declared through
events.subscribe, recorded verbatim (the guest-chosenhandlerid + the WITfilter). The host drains these afterregister-eventsreturns and wires each to the nativeEventBus(PH7.8c); the filter projects to native at wire time viaboundary_event::project_event_filter.