We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 29da763 + e4ffea8 commit dee84e9Copy full SHA for dee84e9
examples/completion.rs
@@ -29,10 +29,14 @@ impl Default for MyCompletion {
29
impl Completion for MyCompletion {
30
/// Simple completion implementation based on substring
31
fn get(&self, input: &str) -> Option<String> {
32
- let s = input.to_string();
33
- let ss: Vec<&String> = self.options.iter().filter(|x| s == x[..s.len()]).collect();
34
- if ss.len() == 1 {
35
- Some(ss[0].to_string())
+ let matches = self
+ .options
+ .iter()
+ .filter(|option| option.starts_with(input))
36
+ .collect::<Vec<_>>();
37
+
38
+ if matches.len() == 1 {
39
+ Some(matches[0].to_string())
40
} else {
41
None
42
}
0 commit comments