Skip to main content

CommandQueryService

Trait CommandQueryService 

Source
pub trait CommandQueryService:
    Service
    + Send
    + Sync {
    // Required methods
    fn search_by_prefix(&self, prefix: &str) -> Vec<CommandInfo>;
    fn find_by_name(&self, name: &str) -> Option<CommandInfo>;
    fn list_user_commands(&self) -> Vec<CommandInfo>;
    fn list_all(&self) -> Vec<CommandInfo>;
    fn count(&self) -> usize;
}
Expand description

Query service for command discovery and completion.

Modules access this via ServiceRegistry to implement features like tab-completion without depending on runner internals.

§Thread Safety

Implementations must be thread-safe (Send + Sync).

§Example

// In cmdline module for tab completion:
let query = services.get::<dyn CommandQueryService>()?;
let matches = query.search_by_prefix("wri");
// matches contains CommandInfo for "write", etc.

Required Methods§

Source

fn search_by_prefix(&self, prefix: &str) -> Vec<CommandInfo>

Search commands by name prefix (for tab completion).

Returns commands where any alias starts with prefix. The search is case-sensitive. An empty prefix returns all commands (every string starts with "").

§Example
let matches = query.search_by_prefix("wri");
// Returns CommandInfo for commands with aliases like "write"
Source

fn find_by_name(&self, name: &str) -> Option<CommandInfo>

Find command by exact name or alias.

§Example
let info = query.find_by_name("w");
// Returns Some(CommandInfo) for the :write command
Source

fn list_user_commands(&self) -> Vec<CommandInfo>

List all commands that have user-facing names.

Returns only commands where names() is non-empty. Use this for cmdline completion UI.

Source

fn list_all(&self) -> Vec<CommandInfo>

List all registered commands.

Includes commands without ex-names (internal commands).

Source

fn count(&self) -> usize

Get total command count.

Implementors§