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
impl CommandContext
Sourcepub fn new() -> CommandContext
pub fn new() -> CommandContext
Create a new empty command context.
Sourcepub fn buffer_id(&self) -> Option<BufferId>
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.
Sourcepub fn set_buffer_id(&mut self, id: BufferId)
pub fn set_buffer_id(&mut self, id: BufferId)
Set the active buffer ID.
Called by the runner before dispatching a command.
Sourcepub fn window_id(&self) -> Option<WindowId>
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.
Sourcepub fn set_window_id(&mut self, id: WindowId)
pub fn set_window_id(&mut self, id: WindowId)
Set the active window ID.
Called by the runner before dispatching a command.
Sourcepub fn with_vfs(self, vfs: Arc<dyn VfsDriver>) -> CommandContext
pub fn with_vfs(self, vfs: Arc<dyn VfsDriver>) -> CommandContext
Sourcepub fn set_vfs(&mut self, vfs: Arc<dyn VfsDriver>)
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.
Sourcepub fn vfs(&self) -> Option<&Arc<dyn VfsDriver>>
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.
Sourcepub fn set_mode_name(&mut self, mode: impl Into<String>)
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.
Sourcepub fn mode_name(&self) -> Option<&str>
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.
Sourcepub fn is_operator_pending(&self) -> bool
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.
Sourcepub fn char(&self, name: &str) -> Option<char>
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).
Sourcepub fn range_start(&self) -> Option<(usize, usize)>
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.
Sourcepub fn range_end(&self) -> Option<(usize, usize)>
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.
Sourcepub fn is_linewise(&self) -> bool
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.
Sourcepub fn bool_flag(&self, name: &str) -> bool
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.
Sourcepub fn cursor_position(&self) -> Option<Position>
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...
}Sourcepub fn set_cursor_position(&mut self, pos: Position)
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
impl Clone for CommandContext
Source§fn clone(&self) -> CommandContext
fn clone(&self) -> CommandContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more