lattice_grammar/target.rs
1//! `Target`: the value an operator operates on.
2//!
3//! A `Target` resolves (via the dispatcher) to a structural buffer range. It
4//! can be a motion (consumed by following the motion's evaluator from the
5//! current cursor), a text-object (consumed by evaluating the text-object at
6//! the current cursor), or an explicit grammar `Range` (line range, mark
7//! range, `:%`, current selection, etc.).
8
9use serde::{Deserialize, Serialize};
10
11use crate::args::Args;
12use crate::range::Range;
13use crate::registry::{MotionId, TextObjectId};
14
15/// What an operator acts on: the `w` in `dw`, the `iw` in `diw`, the `%` in
16/// `:%d`. The dispatcher resolves it against the document and cursor to a
17/// concrete span before calling the operator.
18///
19/// An invocation's explicit `range` wins over its `target` when both are
20/// set; an operator with neither fails with
21/// [`crate::CommandError::MissingTarget`].
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23pub enum Target {
24 /// Run the motion from the cursor; the span is cursor..landing point,
25 /// with the motion's own inclusive / linewise flags deciding the ends.
26 /// The [`Args`] are the motion's own (e.g. the char for `f<c>`). If the
27 /// motion cannot move, the operator is cancelled
28 /// ([`crate::CommandError::MotionFailed`]).
29 Motion(MotionId, Args),
30 /// Evaluate the text object at the cursor (`iw`, `a(`, tree-sitter
31 /// `af`); the span is whatever it selects. [`Args`] as for `Motion`.
32 TextObject(TextObjectId, Args),
33 /// An explicit grammar [`Range`] -- line range, marks, `%`, or the
34 /// current Visual selection.
35 Range(Range),
36}