Skip to main content

ActionContext

Struct ActionContext 

Source
pub struct ActionContext {
    pub args: Args,
    pub register: Register,
    pub count: Count,
    pub cursor: Position,
    pub buffer_id: BufferId,
    pub buffer: Buffer,
    pub selection: Option<Range>,
    pub syntax: Option<Arc<dyn Any + Send + Sync>>,
    pub cancel: CancellationToken,
    pub path: Option<Arc<PathBuf>>,
}
Expand description

Context passed to a free-form action’s evaluator. Mirrors ExCommandContext’s shape (no document mutation; the App applies the returned crate::effect::Effect) but omits the bang bit – chord-bound actions never carry one. The register / count slots flow the count and register prefixes the user typed before the chord (vim’s 3"+yy-style); most actions ignore them.

Fields§

§args: Args

The action’s arguments; usually Args::None.

§register: Register

The "x prefix typed before the chord, unnamed by default.

§count: Count

The count typed before the chord, 1 by default.

§cursor: Position

Where the caret sits when the action fires (AP.0.1) — the action’s equivalent of MotionContext::from. Native actions ignore it; a plugin action pairs it with buffer (below) to read the text around the cursor.

§buffer_id: BufferId

The active buffer’s id (AP.2) — the target a plugin action names in an Effect::ApplyEdit. Mirrors MotionContext::buffer_id.

§buffer: Buffer

A point-in-time view of the buffer the action fired in (AP.0.1). An owned Buffer — a ropey::Rope clone is O(1) (Arc-shared nodes), so carrying it costs nothing on the dispatch path and avoids a context lifetime. Native actions ignore it; the plugin-host trampoline mints a document resource from it so a grammar plugin can read buffer text. Layering: a lattice-core type, so lattice-grammar needs no lattice-runtime dependency (the snapshot is built host-side).

§selection: Option<Range>

OS.2: the active region — the Visual/Select selection extent, normalised so start <= end. None in Normal mode and on every non-chord firing path (prompt submit, transient item, a Confirm yes-action).

The peer of lattice_mode::ActionContext::selection (MG.18e), which native mode handlers have had since magit needed to stage part of a hunk. A plugin action reached the same way saw strictly less — the position OC.10 fixed for ex-command-context. Carried in from GrammarEnv::selection so both contexts quote one resolver.

Carries no visual kind, matching the field it mirrors: every consumer so far reads the row span, and inventing a charwise/blockwise contract before something holds it would be inventing a promise.

§syntax: Option<Arc<dyn Any + Send + Sync>>

TS.1: a point-in-time tree-sitter snapshot for the buffer the action fired in, type-erased as Arc<dyn Any> so lattice-grammar keeps its protocol+core-only dep set (the same reason buffer is a lattice-core type — a concrete SyntaxSnapshot would drag the whole syntax stack under the lean grammar crate). The host upcasts the buffer’s Arc<SyntaxSnapshot> here at the same instant it clones buffer (so tree + text versions agree); native actions ignore it; the plugin-host trampoline downcasts it to mint a tree-snapshot resource so a grammar plugin can query structure (auto-pair’s enclosing scope). None when the buffer has no parse (plain text / parse pending).

§cancel: CancellationToken

Cooperative cancellation handle (DESIGN.md §5.2.5). Most actions are O(1) state mutations and ignore this; long- running ones (a hypothetical “rebuild fold tree” action) poll cancel.check()? between iterations.

§path: Option<Arc<PathBuf>>

OM.6b: the file the action’s buffer is backed by, so a plugin action’s document handle can answer path() — the question org-archive-subtree asks to name <file>_archive.

Owned, unlike the motion and text-object peers, because this context is owned; Arc<PathBuf> rather than PathBuf so it is an Arc bump per dispatch and not an allocation. None for a buffer with no file.

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
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.

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