Skip to main content

Module event_registry

Module event_registry 

Source
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:

  • Event trait – marker every concrete event type implements (Any + Debug + Send + Sync + 'static).
  • EventTypeId – thin wrapper over std::any::TypeId keyed against an interned name; the registry surfaces the name for introspection (:describe-events).
  • EventDescriptor – per-event metadata (name, doc, source crate). Aggregated process-wide via EVENT_DESCRIPTORS (a linkme distributed slice; same mechanism lattice-config uses for typed options).
  • register_event! macro – single declaration site that pushes the descriptor and implements Event.
  • A runtime registry for plugin-defined events, which cannot be in a link-time slice: register_runtime_event / unregister_runtime_event, with all_events / event_info_by_name as 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§

EventDescriptor
Per-event metadata aggregated into EVENT_DESCRIPTORS. :describe-events walks this slice; subscriber tooling (future “wait-for-event” debuggers, plugin host) can also enumerate it.
EventInfo
Owned, source-tagged view of an event descriptor. Merges the two registries: the compile-time EVENT_DESCRIPTORS linkme 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.
EventTypeId
Stable identifier for an event type. Pairs Rust’s std::any::TypeId (the bus’s downcast key) with a string name (what :describe-events prints). Hash / Eq use the TypeId only – 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 with register_event! fails to compile (conflicting Event impls), but two types sharing a name both land in EVENT_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. linkme aggregates entries across crates at link time – same mechanism lattice-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: Any for the cast, Send + Sync + 'static for cross-thread shipping, Debug for 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 None when 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-events when invoked off a publisher’s event_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 false and 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 returns false if 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 name themselves.
unregister_runtime_event
Remove a runtime event (plugin unload / reload). No-op for an unknown name.