From 261116d4b445dd10b6ea8756350c97484d370cc1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 9 Aug 2024 13:56:47 -0500 Subject: [PATCH] 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. --- clap_complete/src/dynamic/complete.rs | 2 +- clap_complete/src/dynamic/custom.rs | 10 ++++++---- clap_complete/tests/testsuite/dynamic.rs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/clap_complete/src/dynamic/complete.rs b/clap_complete/src/dynamic/complete.rs index e0ea4efc..6b5807f7 100644 --- a/clap_complete/src/dynamic/complete.rs +++ b/clap_complete/src/dynamic/complete.rs @@ -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())); diff --git a/clap_complete/src/dynamic/custom.rs b/clap_complete/src/dynamic/custom.rs index 5a424550..2c03a765 100644 --- a/clap_complete/src/dynamic/custom.rs +++ b/clap_complete/src/dynamic/custom.rs @@ -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 { - self.0.completions() + pub fn candidates(&self) -> Vec { + 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; + fn candidates(&self) -> Vec; } impl CustomCompleter for F where F: Fn() -> Vec + Send + Sync, { - fn completions(&self) -> Vec { + fn candidates(&self) -> Vec { self() } } diff --git a/clap_complete/tests/testsuite/dynamic.rs b/clap_complete/tests/testsuite/dynamic.rs index 31214fa1..63f59a87 100644 --- a/clap_complete/tests/testsuite/dynamic.rs +++ b/clap_complete/tests/testsuite/dynamic.rs @@ -597,7 +597,7 @@ fn suggest_custom_arg_value() { struct MyCustomCompleter {} impl CustomCompleter for MyCustomCompleter { - fn completions(&self) -> Vec { + fn candidates(&self) -> Vec { vec![ CompletionCandidate::new("custom1"), CompletionCandidate::new("custom2"),