pub trait AutocompleteProvider: Send + Sync {
// Required methods
fn can_autocomplete(&self) -> bool;
fn get_displayable_suggestion(
&self,
current_input: String,
) -> Option<String>;
fn get_tab_completion(
&self,
last_completion_index: Option<usize>,
input: &str,
) -> Option<String>;
}Expand description
Something that can provide auto-complete results.
Lisa has built this interface in such a way to make it easy to write relatively stateless, if not fully ZST auto complete providers. The current input provider should store the ‘auto-complete’ state, along with determining when to call the autocomplete provider.
It should also be important to note that not all input mechanisms may support an autocomplete system (e.g. if you accept HTTP API calls in, you may not need autocomplete at all).
Please consult your input providers documentation for more information about how it does, or does not use autocomplete.
Your autocomplete provider should be fast as if provided it can delay user input from rendering which may cause a suboptimal user experience.
Required Methods§
Sourcefn can_autocomplete(&self) -> bool
fn can_autocomplete(&self) -> bool
Whether or not this autocomplete provider can actually provide autocompletes.
Sourcefn get_displayable_suggestion(&self, current_input: String) -> Option<String>
fn get_displayable_suggestion(&self, current_input: String) -> Option<String>
Get the characters to display after a users current input as a suggestion.
This should return only the net new characters to add to
current_input to make a full command. While this value should be cached
by the display provider, it is dependent on which display provider you
are using. Even in a cached world though this function should return
fast as it will impact the display rendering time when called.
Sourcefn get_tab_completion(
&self,
last_completion_index: Option<usize>,
input: &str,
) -> Option<String>
fn get_tab_completion( &self, last_completion_index: Option<usize>, input: &str, ) -> Option<String>
Get the characters to add to an input when a user hits ‘tab’.
This should return the net new characters to add to input to complete
the completion.
The ‘last completion index’ is just a counter that goes up to keep track of which particular completion to complete too. If there isn’t another completion for the index, you should wrap around and return the next completion.