Skip to main content

CompleteCtx

Struct CompleteCtx 

Source
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: usize

Which of words the cursor is in.

§prefix: &'a str

What 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>

Source

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.

Source

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.

Source

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.

Source

pub fn previous(&self) -> Option<&'a str>

The word before the one being completed, which is what mise’s {{words[PREV]}} means.

Trait Implementations§

Source§

impl<'a> Clone for CompleteCtx<'a>

Source§

fn clone(&self) -> CompleteCtx<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for CompleteCtx<'a>

Source§

impl<'a> Debug for CompleteCtx<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CompleteCtx<'a>

§

impl<'a> RefUnwindSafe for CompleteCtx<'a>

§

impl<'a> Send for CompleteCtx<'a>

§

impl<'a> Sync for CompleteCtx<'a>

§

impl<'a> Unpin for CompleteCtx<'a>

§

impl<'a> UnsafeUnpin for CompleteCtx<'a>

§

impl<'a> UnwindSafe for CompleteCtx<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.