From 7eadbd938dda5a63cf81ef36b5322df589d86c5b Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 8 Jun 2021 14:31:39 +1200 Subject: [PATCH] Add support for subcommand completions (#3571) * Add support for subcommand completions * Update test * WIP * Fix prepend for completions * Fix test --- crates/nu-cli/src/completion/engine.rs | 51 ++++++++++++++++++++++---- crates/nu-cli/src/shell/completer.rs | 9 ++++- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/crates/nu-cli/src/completion/engine.rs b/crates/nu-cli/src/completion/engine.rs index f99a6c1fab..7bece6993a 100644 --- a/crates/nu-cli/src/completion/engine.rs +++ b/crates/nu-cli/src/completion/engine.rs @@ -203,7 +203,8 @@ pub fn completion_location(line: &str, block: &Block, pos: usize) -> Vec Vec vec![loc], + _ => vec![loc.clone()], }; } else if pos < loc.span.start() { break; @@ -236,14 +254,25 @@ pub fn completion_location(line: &str, block: &Block, pos: usize) -> Vec { let path_completer = PathCompleter; + let prepend = Span::new(pos, location.span.start()).slice(line); const QUOTE_CHARS: &[char] = &['\'', '"', '`']; @@ -103,7 +104,11 @@ impl NuCompleter { } .into_iter() .map(|s| Suggestion { - replacement: requote(s.suggestion.replacement), + replacement: format!( + "{}{}", + prepend, + requote(s.suggestion.replacement) + ), display: s.suggestion.display, }) .collect()