pub trait CommandHandler: Command {
// Required method
fn execute(
&self,
runtime: &mut SessionRuntime<'_>,
args: &CommandContext,
) -> CommandResult;
}Expand description
Command execution trait.
Commands that can be executed implement this trait in addition to Command.
§Design Philosophy
Separating execution from metadata allows:
- Querying command info without execution capability
- Different execution strategies (sync, async, background)
- Testing command metadata independently
§Session Runtime
Commands receive a SessionRuntime which provides access to:
ModeApi- Mode stack operations (push, pop, set)BufferApi- Buffer content and cursor operationsWindowApi- Window management and focusExtensionApi- Per-session module stateChangeTracker- State change accumulation
For operations not yet covered by these APIs, use the escape hatch:
ⓘ
let kernel = runtime.kernel();
let buffer = kernel.buffers.get(buffer_id)?;§Example
ⓘ
use reovim_driver_command::{Command, CommandHandler, CommandContext, CommandResult};
use reovim_driver_session::{SessionRuntime, ModeApi, TransitionContext};
use reovim_kernel::api::v1::{CommandId, ModuleId};
struct EnterInsertMode;
impl Command for EnterInsertMode {
fn id(&self) -> CommandId {
CommandId::new(ModuleId::new("vim"), "enter-insert-mode")
}
fn description(&self) -> &'static str { "Enter insert mode" }
}
impl CommandHandler for EnterInsertMode {
fn execute(&self, runtime: &mut SessionRuntime<'_>, _args: &CommandContext) -> CommandResult {
let insert_mode = ModeId::new(ModuleId::new("vim"), "insert");
runtime.set_mode(insert_mode, TransitionContext::new());
CommandResult::Success
}
}Required Methods§
Sourcefn execute(
&self,
runtime: &mut SessionRuntime<'_>,
args: &CommandContext,
) -> CommandResult
fn execute( &self, runtime: &mut SessionRuntime<'_>, args: &CommandContext, ) -> CommandResult
Execute the command.
§Arguments
runtime- Session runtime providing API trait access and kernel escape hatchargs- The command arguments parsed from user input
§Returns
A CommandResult indicating success, error, or special results like quit.