pub struct CommandNameIndex { /* private fields */ }Expand description
Name-based command index for ex-command resolution.
Maps command names to their CommandId and the underlying Command
trait object (for complete() delegation).
§Lifecycle
- Server builds this at bootstrap from
CommandRegistry - Stored in
ServiceRegistryasArc<CommandNameIndex> - Modules query it for name→id resolution and tab-completion
Implementations§
Source§impl CommandNameIndex
impl CommandNameIndex
Sourcepub fn insert(&mut self, name: String, id: CommandId, cmd: Arc<dyn Command>)
pub fn insert(&mut self, name: String, id: CommandId, cmd: Arc<dyn Command>)
Insert a command by name.
Each name (alias) maps to the same CommandId and Command.
Last-wins if the same name is inserted twice.
Sourcepub fn resolve(&self, name: &str) -> Option<&CommandId>
pub fn resolve(&self, name: &str) -> Option<&CommandId>
Resolve a command name to its CommandId.
Sourcepub fn resolve_entry(&self, name: &str) -> Option<(&CommandId, &dyn Command)>
pub fn resolve_entry(&self, name: &str) -> Option<(&CommandId, &dyn Command)>
Resolve a command name to its CommandId and Command trait object.
Unlike resolve(), this returns the full entry so
callers can access Command::args() for spec-driven argument binding.
Sourcepub fn resolve_prefix(
&self,
name: &str,
) -> Result<Option<(&CommandId, &dyn Command)>, AmbiguousPrefix>
pub fn resolve_prefix( &self, name: &str, ) -> Result<Option<(&CommandId, &dyn Command)>, AmbiguousPrefix>
Resolve a command by exact name or unambiguous prefix.
Resolution order:
- Exact match — returned immediately (highest priority)
- Prefix search — if exactly one distinct command matches, return it
- Multiple aliases of the same command are deduplicated (not ambiguous)
- Multiple distinct commands — return
AmbiguousPrefixerror
Returns Ok(None) for empty input or no matches.
§Errors
Returns AmbiguousPrefix when the prefix matches two or more
distinct commands (e.g., :s matching both :set and :split).
Sourcepub fn complete_args(&self, name: &str, partial: &str) -> Vec<String>
pub fn complete_args(&self, name: &str, partial: &str) -> Vec<String>
Get argument completions for a named command.
Delegates to the command’s complete() method.
Sourcepub fn search_by_prefix(&self, prefix: &str) -> Vec<(&CommandId, &dyn Command)>
pub fn search_by_prefix(&self, prefix: &str) -> Vec<(&CommandId, &dyn Command)>
Search for commands whose names start with prefix.
Returns deduplicated results (one entry per unique CommandId).