Skip to main content

OperatorContext

Struct OperatorContext 

Source
pub struct OperatorContext<'a> {
Show 14 fields pub document: &'a mut Document, pub buffer_id: BufferId, pub range: Range, pub origin: Position, pub linewise: bool, pub register: Register, pub count: Count, pub args: Args, pub cancel: &'a CancellationToken, pub indent: IndentUnit, pub indent_resolver: Option<&'a dyn IndentResolver>, pub textwidth: WrapWidth, pub comment_syntax: Option<&'a CommentSyntax>, pub native_format: NativeFormatIntents,
}
Expand description

Context passed to an operator’s evaluator.

Fields§

§document: &'a mut Document

The document to edit. Native operators apply their edits here directly (as one undo unit) and report them in the returned Effect; plugin operators hold a read-only view and return an ApplyEdit effect instead.

§buffer_id: BufferId

CM.3: the buffer the operator is running over — the target a plugin operator names in an apply-edit effect.

Absent until now, and the absence was an asymmetry rather than a decision, exactly as MR.2 found for ExCommandContext::buffer_id: ActionContext and MotionContext both carry it, a native operator never needed it because it mutates document in place, and a PLUGIN operator cannot — it holds a read-only handle and must ask the host to apply. Without this field a plugin operator can read its range and never change it, which makes the contribution pointless.

§range: Range

The span to operate on, already resolved from the target or range and expanded to whole lines when Self::linewise.

§origin: Position

VM.3m: the start of the operated text BEFORE linewise expansion — min(cursor, motion target) for a motion, the object’s or selection’s start otherwise, the cursor for a count / current-line / ex range. vim leaves the cursor here after a yank, which is why the expanded range can’t answer: yk keeps its column (k’s target has it) and yy doesn’t move at all, though both expand to whole lines.

§linewise: bool

Whether the range was produced by a linewise source (vim’s Range::CurrentLine / Range::Whole, or a linewise visual selection). Yank uses this to tag the unnamed register so paste can do the right thing.

§register: Register

The register the operator reads or writes (unnamed when none typed).

§count: Count

The count, 1 when none was typed. Usually already folded into the span by target resolution (3dw), so most operators ignore it.

§args: Args

The operator’s own arguments, e.g. the captured char for r{char} or surround’s ys{motion}{char}.

§cancel: &'a CancellationToken

Cooperative cancellation handle (DESIGN.md §5.2.5). Operators that scan large ranges (d_whole, gU over a big visual block) should poll cancel.check()? between rows; on a flipped token return crate::CommandError::Cancelled.

§indent: IndentUnit

IN.0: one level of indentation, resolved by the host. Only the indent operators (> / <) read it.

§indent_resolver: Option<&'a dyn IndentResolver>

IN.7: per-line indent depth for the = operator, injected by the host. None (the default) means = has no structural source and leaves lines alone – the same graceful-degradation contract every other env field carries.

§textwidth: WrapWidth

RF.2: the buffer’s textwidth, resolved by the host (including any :setlocal). Read by the reflow operator (gq / gw).

Not an Option, for the same reason Self::indent is not: there is always a defensible answer, and WrapWidth::default() is the registered option default, so a caller that never resolved config reflows like an unconfigured buffer rather than not at all.

§comment_syntax: Option<&'a CommentSyntax>

RF.2: the buffer language’s line-comment leader, so reflow can keep a comment block’s marker. None for prose languages and for any language whose comment syntax is undeclared – reflow then uses indentation alone, which is the right answer there.

§native_format: NativeFormatIntents

RF.5b: for each intent, whether the buffer’s chain resolves to the native engine.

The host resolves the chain — it owns the LSP client and the PATH probe — and hands down the one bit the operator needs: “do it yourself, or hand me the range”. true (the default) is the shipped configuration, so the common path never delegates.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for OperatorContext<'a>

§

impl<'a> !Send for OperatorContext<'a>

§

impl<'a> !Sync for OperatorContext<'a>

§

impl<'a> !UnwindSafe for OperatorContext<'a>

§

impl<'a> Freeze for OperatorContext<'a>

§

impl<'a> Unpin for OperatorContext<'a>

§

impl<'a> UnsafeUnpin for OperatorContext<'a>

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