Skip to main content

lattice_plugin_loader/
events.rs

1//! LA.1 — typed events the loader publishes about the **mode/language
2//! catalog**, as distinct from the plugin lifecycle.
3//!
4//! `Event::PluginLoaded` already fires once per load, but it says "a plugin
5//! finished loading", not "the set of languages and major modes the editor can
6//! resolve against just changed". Those are different facts with different
7//! subscribers: the first is what an `init.rs` `on-plugin-loaded` handler
8//! waits for; the second is what makes an already-open buffer's major mode
9//! stale (`mode-architecture.md` §7.4, "Major mode, second trigger").
10//!
11//! Keeping them apart is what keeps the re-resolution cheap. Re-running the
12//! ordered major resolver is O(major-modes × open buffers); riding
13//! `PluginLoaded` would pay that for every auto-pair-shaped plugin that cannot
14//! possibly have changed the answer.
15
16use lattice_plugin_host::PluginId;
17
18/// Fired **once per plugin load** whose drain could have changed the
19/// mode/language catalog — i.e. the manifest declared `language` or `modes`.
20///
21/// Published after the plugin's *entire* drain completes, never per registered
22/// language: a subscriber re-resolving major modes must see a fully-installed
23/// catalog, and a plugin that ships a language *and* the major mode that binds
24/// it would otherwise be observed half-way through.
25///
26/// Declared-seam gated rather than registered-count gated. A plugin whose every
27/// language was rejected publishes anyway, which costs one wasted re-resolution
28/// that finds nothing; the inverse mistake — deriving the gate from what
29/// actually registered — would need each drain to report a count upward, and a
30/// drain that forgot to would fail silently in exactly the way this whole area
31/// keeps failing.
32#[derive(Debug, Clone)]
33pub struct LanguagesRegistered {
34    /// The host-issued id of the plugin whose load changed the catalog. The
35    /// plugin's *user-facing* identity is its manifest name, carried by
36    /// `Event::PluginLoaded`; this id is here so a subscriber can correlate the
37    /// two, not so it can look anything up.
38    pub plugin: PluginId,
39}
40
41lattice_protocol::register_event!(
42    LanguagesRegistered,
43    "plugin.languages-registered",
44    "Fired once after a plugin that declares languages or major modes finishes loading, \
45     signalling that the mode/language catalog changed.",
46    "lattice-plugin-loader",
47);