From 76d17abd5c7dad1c7f9aa9cefb5413ec25941f01 Mon Sep 17 00:00:00 2001 From: Ayan Banerjee Date: Sun, 21 Apr 2024 01:28:22 +0530 Subject: [PATCH] fix: panic on completion for an alias (#12090) --- .../src/completions/command_completions.rs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/nu-cli/src/completions/command_completions.rs b/crates/nu-cli/src/completions/command_completions.rs index 42094f9c97..28a51208f8 100644 --- a/crates/nu-cli/src/completions/command_completions.rs +++ b/crates/nu-cli/src/completions/command_completions.rs @@ -186,13 +186,25 @@ impl Completer for CommandCompletion { // The last item here would be the earliest shape that could possible by part of this subcommand let subcommands = if let Some(last) = last { - self.complete_commands( - working_set, - Span::new(last.0.start, pos), - offset, - false, - options.match_algorithm, - ) + // we'll check if start of span is greater than offset, to prevent panic + // else we can use the start and end values from last and use that. + if last.0.start >= offset { + self.complete_commands( + working_set, + Span::new(last.0.start, pos), + offset, + false, + options.match_algorithm, + ) + } else { + self.complete_commands( + working_set, + Span::new(last.0.start, last.0.end), + offset, + false, + options.match_algorithm, + ) + } } else { vec![] };