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: ArgsThe action’s arguments; usually Args::None.
register: RegisterThe "x prefix typed before the chord, unnamed by default.
count: CountThe count typed before the chord, 1 by default.
cursor: PositionWhere 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: BufferIdThe active buffer’s id (AP.2) — the target a plugin action
names in an Effect::ApplyEdit. Mirrors MotionContext::buffer_id.
buffer: BufferA 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: CancellationTokenCooperative 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.