From b5f8c1cc50e41c274322b73c3bc5b0a0cef89d29 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 8 Dec 2019 19:23:31 +1300 Subject: [PATCH] param completions work now --- src/shell/completer.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/shell/completer.rs b/src/shell/completer.rs index dffb337df9..fc089a3abd 100644 --- a/src/shell/completer.rs +++ b/src/shell/completer.rs @@ -21,6 +21,7 @@ impl NuCompleter { let commands: Vec = self.commands.names(); let line_chars: Vec<_> = line[..pos].chars().collect(); + let mut replace_pos = line_chars.len(); while replace_pos > 0 { if line_chars[replace_pos - 1] == ' ' { @@ -29,9 +30,11 @@ impl NuCompleter { replace_pos -= 1; } - // See if we're a flag + let substring = line_chars[replace_pos..pos].iter().collect::(); + let mut completions = vec![]; + // See if we're a flag if pos > 0 && line_chars[replace_pos] == '-' { let mut line_copy = line.to_string(); let replace_string = (replace_pos..pos).map(|_| " ").collect::(); @@ -66,10 +69,14 @@ impl NuCompleter { { if let Some(named) = args.named { for (name, _) in named.iter() { - completions.push(rustyline::completion::Pair { - display: format!("--{}", name), - replacement: format!("--{}", name), - }); + let full_flag = format!("--{}", name); + + if full_flag.starts_with(&substring) { + completions.push(rustyline::completion::Pair { + display: full_flag.clone(), + replacement: full_flag, + }); + } } } }