Expand description
The open, typed half of the event system: feature crates and plugins declare their own event types here, and introspection lists them.
Typed-event surface (mode-architecture §5.10 follow-up).
The legacy crate::Event enum is the closed catalogue of
editor-core events (DocumentOpened, DocumentChanged, etc.).
Feature crates (lattice-lsp, lattice-completion, future
plugins) need to declare and own their events without
editing the central enum – the same ownership model
lattice-mode uses for Mode declarations.
This module adds:
Eventtrait – marker every concrete event type implements (Any + Debug + Send + Sync + 'static).EventTypeId– thin wrapper overstd::any::TypeIdkeyed against an interned name; the registry surfaces the name for introspection (:describe-events).EventDescriptor– per-event metadata (name, doc, source crate). Aggregated process-wide viaEVENT_DESCRIPTORS(alinkmedistributed slice; same mechanismlattice-configuses for typed options).register_event!macro – single declaration site that pushes the descriptor and implementsEvent.- A runtime registry for plugin-defined events, which cannot be in a
link-time slice:
register_runtime_event/unregister_runtime_event, withall_events/event_info_by_nameas the merged built-in ∪ runtime view (EventInfo).
The runtime’s lattice_runtime::EventBus (M.5.3.a follow-
up) accepts both shapes: legacy enum publishes via
publish / subscribe, typed events via
publish_typed::<T> / subscribe_typed::<T>. Built-in
events stay on the legacy path until a future cleanup slice
migrates them; new events (LSP and beyond) declare via the
typed path.
Structs§
- Event
Descriptor - Per-event metadata aggregated into
EVENT_DESCRIPTORS.:describe-eventswalks this slice; subscriber tooling (future “wait-for-event” debuggers, plugin host) can also enumerate it. - Event
Info - Owned, source-tagged view of an event descriptor. Merges the two registries:
the compile-time
EVENT_DESCRIPTORSlinkme slice (built-in events) and the runtime registry (plugin-defined events, PH7.8b). Introspection + completion (:describe-events,:describe-event,gen:events) read this unified view so a plugin’s custom event surfaces exactly like a built-in one. - Event
Type Id - Stable identifier for an event type. Pairs Rust’s
std::any::TypeId(the bus’s downcast key) with a string name (what:describe-eventsprints). Hash / Eq use theTypeIdonly – two registrations with the same struct but different names would collide on the bus side, which is the behaviour we want. Nothing detects such a duplicate: registering the same type twice withregister_event!fails to compile (conflictingEventimpls), but two types sharing a name both land inEVENT_DESCRIPTORS, and the by-name lookups return whichever the linker placed first.
Statics§
- EVENT_
DESCRIPTORS - Process-wide distributed slice every
register_event!call pushes into.linkmeaggregates entries across crates at link time – same mechanismlattice-config’s typed-option registry uses.
Traits§
- Event
- Marker trait every concrete event type implements. Required
supertraits give the bus enough to box, store, and
downcast:
Anyfor the cast,Send + Sync + 'staticfor cross-thread shipping,Debugfor diagnostic logs.
Functions§
- all_
events - Every event — built-in (linkme) ∪ runtime (plugin) — as owned
EventInfo, sorted by name. The unified view introspection + completion read. - descriptor_
by_ name - Look up a descriptor by exact name. Returns
Nonewhen no event is registered under that name. - descriptor_
by_ type_ id - Look up a descriptor by
TypeId. Used by the bus to format “unknown subscriber for event X” diagnostics and by:describe-eventswhen invoked off a publisher’sevent_type_id(). - event_
info_ by_ name - Look up any event (built-in or runtime) by exact name.
- register_
runtime_ event - Register a runtime (plugin-defined) event. Idempotent by name (a re-register
overwrites — a plugin reload refreshes its doc). Returns
falseand records nothing if the name collides with a BUILT-IN event: a plugin must not shadow a native event (its subscribers would be ambiguous). Also returnsfalseif the registry lock is poisoned. - registered_
events - Walk every registered event descriptor. Order is
link-determined (not sorted); callers that need a stable
presentation should sort by
namethemselves. - unregister_
runtime_ event - Remove a runtime event (plugin unload / reload). No-op for an unknown name.