Skip to main content

SnippetMode

Struct SnippetMode 

Source
pub struct SnippetMode { /* private fields */ }
Expand description

snippet-mode — the base “snippets enabled for this buffer” minor mode (SN.3). The language-aware feature gate: its [ActivationPolicy] decides which buffers get snippets, and it implies SnippetCompletionMode so the completion source rides the same gate (activating snippet-mode brings the source with it — no separate activation).

Three-mode decomposition (confirmed with the user 2026-06-14):

  • snippet-mode (this) — the gate; owns <C-x><C-s> direct-expand (SN.3c; today still host-bound).
  • snippet-completion-mode — provides the gen:snippet completion source only.
  • active-snippet-mode — in-flight placeholder nav (<Tab> / <S-Tab> / <Esc>), lit by the session-backed reconciler when a snippet expands.

SN.3b makes the policy config-driven: the mode reads a shared SnippetActivationPolicyHandle that the host folds snippet.activation / snippet.languages into at boot and on every :set of those keys. The cell defaults to ActivationPolicy::Global (behavior-preserving — the pre-SN.3 language-blind activation on every Document), which is also the folded value when snippet.activation = global (the default).

Implementations§

Source§

impl SnippetMode

Source

pub fn mode_id() -> ModeId

Source

pub fn with_policy(policy: SnippetActivationPolicyHandle) -> Self

Construct with a caller-owned shared policy cell. The host (register_snippet_modes) creates the cell and keeps a clone so boot + :set can re-fold config into it; this mode reads the live value in activation_policy.

Source

pub fn new() -> Self

Construct with a fresh, default-Global policy cell. Used by tests and any caller that doesn’t wire live config folding; the internal cell is private, so the policy is fixed at Global for the mode’s lifetime.

Trait Implementations§

Source§

impl Default for SnippetMode

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Mode for SnippetMode

Source§

fn activation_policy(&self) -> ActivationPolicy

SN.3b: read the live, host-folded policy from the shared cell. Defaults to Global (snippets on every document buffer); the snippet source still self-filters by language, so Global means “each buffer sees its own language’s snippets”, not “all snippets everywhere”. The resolver calls this on each MajorEntered, so a :set snippet.activation takes effect for buffers opened afterward.

Source§

fn implies(&self) -> &[ModeId]

Bring snippet-completion-mode (the source provider) along whenever snippet-mode activates — the source is gated to exactly the buffers where snippets are enabled.

Source§

fn keymap(&self) -> Keymap

SN.3c.1: contribute the <C-x><C-s> direct-expand chord. Registered at boot under KeymapLayer::MinorMode("snippet-mode") (Insert mode); K.1.c gates it to snippet-mode-active buffers.

Source§

fn action_handlers(&self) -> Vec<ActionHandlerContribution>

SN.3c.1: the global (buffer-agnostic) expand handler. Bound to action:snippet-expand, registered ONCE at boot by the host’s register_mode_action_handlers walk (NOT per-on_activate — snippet-mode is active on many buffers at once and the ActionHandlerRegistry is keyed by CommandId alone, so a per-activation registration would let one buffer closing evict the handler for all the others; see feedback_effect_vocabulary_is_host_boundary).

The handler does ONLY the word-prefix scan: read the active buffer’s line at ctx.cursor via the BufferStoreHandle, walk back over word bytes to the trigger token’s start, and emit Effect::ExpandSnippet { replace_range: token-start..cursor }. The host owns resolution + expansion (language + registry + variables + splice). Returns None (no effect) when there is no word prefix at the cursor.

Source§

type Guard = ()

Owned cleanup token returned by [Self::on_activate]. Read more
Source§

fn id(&self) -> ModeId

Canonical identity. Same value every call. Read more
Source§

fn kind(&self) -> ModeKind

Major or minor. Read at registration and on every activation call (activate_major on a minor, or vice versa, is [ModeActivationError::WrongKind]).
Source§

fn required_capabilities(&self) -> CapabilitySet

Capabilities the mode requires. Validated at activation; missing capability ⇒ [ModeActivationError::MissingCapability], never silent skip.
Source§

fn on_activate(&self, _ctx: ModeContext) -> LifecycleFuture<'_, ()>

Lifecycle. Called once per (buffer, activation) cycle after the registry has applied the declarative contributions. Returns an owned Guard carrying every resource the mode allocated. The dispatcher stashes the Guard until deactivation, at which point dropping it performs cleanup via the Guard’s Drop impl. Read more
§

fn target_buffer_kind(&self) -> Option<BufferKind>

For major modes, the [BufferKind] this mode is the default major for (H.2, 2026-05-31). ModeRegistry::register indexes this so ModeRegistry::find_major_for_kind can dispatch buffer-creation events to the right major without host-side match BufferKind { ... } blocks. Read more
§

fn target_language(&self) -> Option<&str>

For major modes, the language this mode is the default major for, by canonical name (Lang::name() — "rust", "org") (OM.1). The peer of target_buffer_kind for the dispatch path [BufferKind::Document] takes: language detection rather than kind dispatch. Read more
§

fn options(&self) -> OptionOverrideSet

Option overrides this mode contributes. Pure declarative (same return value every call); the host merges these into the buffer’s option-resolution layer stack while the mode is active, at the mode’s layer (later-activated minors win ties), and drops them on deactivation. Build with lattice_config::overrides! { lattice_config::Wrap = true, … }.
§

fn decorations(&self) -> Vec<DecorationProvider>

Decoration providers (gutter / inline / overlay / statusline). Stub — reserved for the WIT plugin path (M.10).
§

fn gutter_decorations(&self, _ctx: &DecorationCtx<'_>) -> Vec<GutterDecoration>

Gutter sign decorations this mode contributes while active. Called once per pane per frame with a [DecorationCtx] carrying relevant render-state snapshots (diff sign map, LSP diagnostics arc). Returns per-line GutterDecoration values; the renderer partitions them by variant into the appropriate gutter column. Default: empty (no contribution).
§

fn completion_sources(&self) -> Vec<CompletionSourceContribution>

Insert-mode completion sources this mode contributes while active on a buffer. Empty by default; minors that own a completion source (lsp-completion-mode, snippet-completion-mode, buffer-words-mode, tree-sitter-completion-mode, path-completion-mode, plugin sources) override.
§

fn conflicts_with(&self) -> &[ModeId]

Modes this one cannot be active alongside. Read more
§

fn presents_extensions(&self) -> &[&'static str]

File extensions (lowercase, no dot) this major PRESENTS rather than edits — the file is never loaded as text. Read more
§

fn mirrors_option(&self) -> Option<&'static str>

Declarative mirror hint for “this mode is the on/off switch for a typed option of the same observable state”. Some(canonical_name) ⇒ a host-driven cascade keeps the mode’s active state and the option’s value in sync.
§

fn invocation_runner(&self) -> Option<ModeId>

Invocation-runner discovery (2026-05-26). Modes that own command-invocation dispatch for their buffer kind (terminal-mode, oil-mode, file-tree-mode, help-mode, …) return their canonical [ModeId]; the host registers a runner function under that id at boot, and Editor::run_invocation looks it up by walking the active modes on the active pane’s buffer (minors first, then major) before falling back to the central grammar Action gate. Read more
§

fn refresh_action(&self) -> Option<&'static str>

Which of this mode’s own actions refreshes its view, or None (the default) when the mode backs nothing refreshable (RV.1, 2026-08-10). Read more
§

fn fold_toggle_action(&self) -> Option<&'static str>

Which of this mode’s actions <Tab> fires, and the declaration that pulls in foldable-view-mode — the shared minor owning the chord. Read more
§

fn refresh_on_open(&self) -> bool

Should re-opening this view re-run its refresh? Read more
§

fn editable_tail(&self) -> Option<EditableTail>

The mode’s editable tail on an otherwise read-only buffer, or None (the default) for a fully read-only / fully writable buffer (AU‑3). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<M> DynMode for M
where M: Mode,

§

fn id(&self) -> ModeId

Forwards to [Mode::id].
§

fn kind(&self) -> ModeKind

Forwards to [Mode::kind].
§

fn target_buffer_kind(&self) -> Option<BufferKind>

Forwards to [Mode::target_buffer_kind].
§

fn target_language(&self) -> Option<&str>

Forwards to [Mode::target_language].
§

fn options(&self) -> OptionOverrideSet

Forwards to [Mode::options].
§

fn keymap(&self) -> Keymap

Forwards to [Mode::keymap].
§

fn decorations(&self) -> Vec<DecorationProvider>

Forwards to [Mode::decorations].
§

fn gutter_decorations(&self, ctx: &DecorationCtx<'_>) -> Vec<GutterDecoration>

Forwards to [Mode::gutter_decorations].
§

fn completion_sources(&self) -> Vec<CompletionSourceContribution>

Forwards to [Mode::completion_sources].
§

fn action_handlers(&self) -> Vec<ActionHandlerContribution>

Forwards to [Mode::action_handlers].
§

fn required_capabilities(&self) -> CapabilitySet

Forwards to [Mode::required_capabilities].
§

fn conflicts_with(&self) -> &[ModeId]

Forwards to [Mode::conflicts_with].
§

fn implies(&self) -> &[ModeId]

Forwards to [Mode::implies].
§

fn presents_extensions(&self) -> &[&'static str]

Forwards to [Mode::presents_extensions].
§

fn mirrors_option(&self) -> Option<&'static str>

Forwards to [Mode::mirrors_option].
§

fn invocation_runner(&self) -> Option<ModeId>

Forwards to [Mode::invocation_runner].
§

fn refresh_action(&self) -> Option<&'static str>

Forwards to [Mode::refresh_action].
§

fn fold_toggle_action(&self) -> Option<&'static str>

Forwards to [Mode::fold_toggle_action].
§

fn refresh_on_open(&self) -> bool

Forwards to [Mode::refresh_on_open].
§

fn activation_policy(&self) -> ActivationPolicy

Forwards to [Mode::activation_policy].
§

fn editable_tail(&self) -> Option<EditableTail>

Forwards to [Mode::editable_tail].
§

fn on_activate_dyn<'a>( &'a self, ctx: ModeContext, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Any + Send>, ModeActivationError>> + Send + 'a>>

Type-erased lifecycle entry. Returns a future whose output is the typed Guard erased to Box<dyn Any + Send>. The dispatcher stashes this box keyed by (BufferId, ModeId); deactivation drops it.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more