pub struct CompleteCtx<'a> {
pub words: &'a [String],
pub cword: usize,
pub prefix: &'a str,
pub command_path: &'a [(&'a Command<'a>, &'a [String])],
pub command_words: &'a [String],
}Expand description
What a completion callback is told about the cursor.
Everything a run= command is given through tera — the words, which one the cursor is in —
plus the prefix, which the reference makes each script filter on and this filters for the
callback. A completer that wants an earlier value on the line reads it from words; one that
wants it typed gets it in the next stage, where the derive can hand over the command’s own
half-parsed struct.
Fields§
§words: &'a [String]The words of the line, unquoted, including the one being completed.
cword: usizeWhich of words the cursor is in.
prefix: &'a strWhat has been typed of that word. Candidates are filtered by it afterwards, so a completer may ignore it and answer with everything it knows.
command_path: &'a [(&'a Command<'a>, &'a [String])]Every command the words passed through, and the words each one was given.
A completer is declared on some command, which is not always the deepest one the line reached — a global flag belongs to an ancestor — so a caller that wants its own command’s words asks for them by that command.
command_words: &'a [String]The words the command in scope was given: after its own name, before the cursor’s word.
What a callback needs to reconstruct its command’s half-parsed struct — mise task ls --file other.toml ⌶ is ["--file", "other.toml"] here, whatever the words before ls
were.
Implementations§
Source§impl<'a> CompleteCtx<'a>
impl<'a> CompleteCtx<'a>
Sourcepub fn command_for(
&self,
declaration: &Command<'_>,
) -> Option<(&'a Command<'a>, &'a [String])>
pub fn command_for( &self, declaration: &Command<'_>, ) -> Option<(&'a Command<'a>, &'a [String])>
The command in the active path that owns declaration, and the words it was given.
Matched by key, not by address: a Subcommands variant builds its own table entry for
the command it names — it may rename it, or give it aliases the type knows nothing about
— so the entry the parse walked is a copy of the one the type declares. The key is a
hash of the type it came from and survives the copying, which makes it the identity two
tables of the same command agree on. Not the name, which a variant can change and two
commands can share.
A flattened group’s command is not itself on the path: its fields were spliced into the parent’s table. In that case the command containing all of the group’s declarations is the owner. Returning that actual command matters as well as returning its words, because reparsing against the flattened table alone would stop at a parent subcommand name and miss a global flag written after it.
Sourcepub fn words_for(&self, command: &Command<'_>) -> &'a [String]
pub fn words_for(&self, command: &Command<'_>) -> &'a [String]
The words command was given, or the deepest command’s if it is not on the path.
The fallback is for a completer reached by name rather than by a cursor position, where there may be no path at all.
Sourcepub fn command_words_start(&self) -> &'a [String]
pub fn command_words_start(&self) -> &'a [String]
The words a parser should walk to find the command this request is about.
After the program name, before the word being completed — the same slice walk is given
for an ordinary request, so a --candidates request resolves the same command an
ordinary one would.
Trait Implementations§
Source§impl<'a> Clone for CompleteCtx<'a>
impl<'a> Clone for CompleteCtx<'a>
Source§fn clone(&self) -> CompleteCtx<'a>
fn clone(&self) -> CompleteCtx<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more