Skip to main content

CommandContext

Struct CommandContext 

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

Context carrying all command inputs.

Provides typed access to arguments parsed from user input, plus optional access to the virtual filesystem for file operations.

§Example

use reovim_driver_command_types::{CommandContext, ArgValue};

let mut ctx = CommandContext::new();
ctx.set("count", ArgValue::Count(5));
ctx.set("register", ArgValue::Register('a'));

assert_eq!(ctx.count(), Some(5));
assert_eq!(ctx.register(), Some('a'));

Implementations§

Source§

impl CommandContext

Source

pub fn new() -> CommandContext

Create a new empty command context.

Source

pub fn set(&mut self, name: &str, value: ArgValue)

Set an argument value.

Source

pub fn get(&self, name: &str) -> Option<&ArgValue>

Get an argument value by name.

Source

pub fn count(&self) -> Option<usize>

Get the count argument, if present.

Source

pub fn register(&self) -> Option<char>

Get the register argument, if present.

Source

pub fn has_bang(&self) -> bool

Check if the bang modifier is set.

Source

pub fn string(&self, name: &str) -> Option<&str>

Get a string argument by name.

Source

pub fn range(&self) -> Option<(usize, usize)>

Get a range argument, if present.

Source

pub fn buffer_id(&self) -> Option<BufferId>

Get the active buffer ID, if present.

The buffer ID is set by the runner before command execution to indicate which buffer the command should operate on.

Source

pub fn set_buffer_id(&mut self, id: BufferId)

Set the active buffer ID.

Called by the runner before dispatching a command.

Source

pub fn window_id(&self) -> Option<WindowId>

Get the active window ID, if present.

The window ID is set by the runner before command execution to indicate which window the command should operate on.

Source

pub fn set_window_id(&mut self, id: WindowId)

Set the active window ID.

Called by the runner before dispatching a command.

Source

pub fn with_vfs(self, vfs: Arc<dyn VfsDriver>) -> CommandContext

Create a command context with VFS access.

Builder method for creating a context with filesystem access.

§Example
let ctx = CommandContext::new().with_vfs(session_state.vfs.clone());
Source

pub fn set_vfs(&mut self, vfs: Arc<dyn VfsDriver>)

Set the VFS for this context.

Called by the runner before dispatching commands that need filesystem access.

Source

pub fn vfs(&self) -> Option<&Arc<dyn VfsDriver>>

Get the VFS driver, if available.

Returns None if no VFS was set for this context. Commands that need filesystem access should check this and return an appropriate error if VFS is unavailable.

Source

pub fn set_mode_name(&mut self, mode: impl Into<String>)

Set the current mode name.

Called by the runner before dispatching commands. Commands can use mode_name() to adjust behavior based on the current mode.

Source

pub fn mode_name(&self) -> Option<&str>

Get the current mode name.

Returns the mode name (e.g., “normal”, “operator-pending”, “insert”). Commands can use this to adjust behavior. For example, motion commands return CommandResult::OperatorRange in operator-pending mode instead of moving the cursor.

Source

pub fn is_operator_pending(&self) -> bool

Check if the current mode is operator-pending.

Convenience method for motion commands to check if they should return a range instead of moving the cursor.

Source

pub fn char(&self, name: &str) -> Option<char>

Get a character argument by name.

Used for commands that need a single character input, such as find-char (f/F/t/T) or replace (r).

Source

pub fn range_start(&self) -> Option<(usize, usize)>

Get the start position for operator ranges (Epic #415).

Returns (line, column) of the range start position.

Source

pub fn range_end(&self) -> Option<(usize, usize)>

Get the end position for operator ranges (Epic #415).

Returns (line, column) of the range end position.

Source

pub fn is_linewise(&self) -> bool

Check if this is a linewise operation (Epic #415).

When true, operators should expand the range to full lines.

Source

pub fn bool_flag(&self, name: &str) -> bool

Get a boolean flag by name.

Returns true only if the named argument is ArgValue::Bool(true). Returns false for missing values, Bool(false), or wrong types.

Source

pub fn cursor_position(&self) -> Option<Position>

Get the cursor position from the active window.

This is the cursor position explicitly passed by the runner from the client’s active window. Commands should use this instead of searching for cursor position through window lookups.

Returns None if cursor was not set. Commands should fail explicitly rather than use a fallback position (Fail Loud Policy).

§Example
fn execute(&self, runtime: &mut SessionRuntime<'_>, args: &CommandContext) -> CommandResult {
    let Some(pos) = args.cursor_position() else {
        return CommandResult::error("No cursor position");
    };
    // Use pos for operation...
}
Source

pub fn set_cursor_position(&mut self, pos: Position)

Set the cursor position from the active window.

Called by the runner before dispatching a command. The runner gets the cursor from the client’s active window and passes it explicitly.

§Why Explicit Passing

A buffer can appear in multiple windows (:split). Using cursor_position(buffer_id) would find the FIRST window with that buffer, which may not be the ACTIVE window. Explicit passing ensures we always use the correct cursor position.

Trait Implementations§

Source§

impl Clone for CommandContext

Source§

fn clone(&self) -> CommandContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for CommandContext

Source§

fn default() -> CommandContext

Returns the “default value” for a type. 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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