pub trait Command:
Send
+ Sync
+ 'static {
// Required methods
fn id(&self) -> CommandId;
fn description(&self) -> &'static str;
// Provided methods
fn args(&self) -> Vec<ArgSpec> { ... }
fn names(&self) -> &[&'static str] { ... }
fn complete(&self, _partial: &str) -> Vec<String> { ... }
fn priority(&self) -> CommandPriority { ... }
}Expand description
Self-describing command metadata.
Commands implement this trait to provide metadata about themselves:
- Unique identifier (
CommandId) - Human-readable description
- Argument specifications
- Command aliases (for ex commands like
:w,:write)
§Design Philosophy
This trait separates command metadata from execution. The CommandHandler
trait handles actual execution. This allows querying command information
without executing.
§Example
use reovim_driver_command::{Command, ArgSpec, ArgKind};
use reovim_kernel::api::v1::{CommandId, ModuleId};
struct DeleteLine;
impl Command for DeleteLine {
fn id(&self) -> CommandId {
CommandId::new(ModuleId::new("editor"), "delete-line")
}
fn description(&self) -> &'static str {
"Delete the current line"
}
fn args(&self) -> Vec<ArgSpec> {
vec![ArgSpec::optional("count", ArgKind::Count, "Number of lines")]
}
}Required Methods§
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
Get a human-readable description of what this command does.
Provided Methods§
Sourcefn args(&self) -> Vec<ArgSpec>
fn args(&self) -> Vec<ArgSpec>
Get the argument specifications for this command.
Returns an empty vector if the command takes no arguments.
Sourcefn names(&self) -> &[&'static str]
fn names(&self) -> &[&'static str]
Get command name aliases.
These are used for ex commands (command-line mode). For example,
:w and :write are aliases for the same command.
Sourcefn complete(&self, _partial: &str) -> Vec<String>
fn complete(&self, _partial: &str) -> Vec<String>
Get tab-completion candidates for this command’s arguments.
Called when the user presses Tab while editing arguments for this command. Returns a list of completion candidates matching the partial input.
Default implementation returns an empty list (no completions).
Sourcefn priority(&self) -> CommandPriority
fn priority(&self) -> CommandPriority
Registration priority (#545).
When multiple handlers register for the same CommandId,
higher priority wins. Equal priority uses last-wins semantics.
Override this to CommandPriority::Override in adapter commands
that replace a base module’s handler.