fix(complete)!: Rename CustomCompleter::completions to candidates

After thinking on this, I feel like it gives a better sense that the
user doesn't get a say in the completion but they give us the options
and we take care of it.
This commit is contained in:
Ed Page 2024-08-09 13:56:47 -05:00
parent 7d14ce34de
commit 261116d4b4
3 changed files with 8 additions and 6 deletions

View file

@ -408,7 +408,7 @@ fn complete_custom_arg_value(
debug!("complete_custom_arg_value: completer={completer:?}, value={value:?}");
let mut values = Vec::new();
let custom_arg_values = completer.completions();
let custom_arg_values = completer.candidates();
values.extend(custom_arg_values);
values.retain(|comp| comp.get_content().starts_with(&value.to_string_lossy()));

View file

@ -34,9 +34,11 @@ impl ArgValueCompleter {
Self(Arc::new(completer))
}
/// All potential candidates for an argument.
///
/// See [`CompletionCandidate`] for more information.
pub fn completions(&self) -> Vec<CompletionCandidate> {
self.0.completions()
pub fn candidates(&self) -> Vec<CompletionCandidate> {
self.0.candidates()
}
}
@ -55,14 +57,14 @@ pub trait CustomCompleter: Send + Sync {
/// All potential candidates for an argument.
///
/// See [`CompletionCandidate`] for more information.
fn completions(&self) -> Vec<CompletionCandidate>;
fn candidates(&self) -> Vec<CompletionCandidate>;
}
impl<F> CustomCompleter for F
where
F: Fn() -> Vec<CompletionCandidate> + Send + Sync,
{
fn completions(&self) -> Vec<CompletionCandidate> {
fn candidates(&self) -> Vec<CompletionCandidate> {
self()
}
}

View file

@ -597,7 +597,7 @@ fn suggest_custom_arg_value() {
struct MyCustomCompleter {}
impl CustomCompleter for MyCustomCompleter {
fn completions(&self) -> Vec<CompletionCandidate> {
fn candidates(&self) -> Vec<CompletionCandidate> {
vec![
CompletionCandidate::new("custom1"),
CompletionCandidate::new("custom2"),