From 80c9888f823432ae04187f2d86dd7c8216114019 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sat, 2 Apr 2022 08:18:11 +1300 Subject: [PATCH] Add command descriptions to completions (#5063) --- crates/nu-cli/src/completions.rs | 4 ++-- crates/nu-protocol/src/engine/engine_state.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/nu-cli/src/completions.rs b/crates/nu-cli/src/completions.rs index 43215fac8..30c60a5fb 100644 --- a/crates/nu-cli/src/completions.rs +++ b/crates/nu-cli/src/completions.rs @@ -150,8 +150,8 @@ impl NuCompleter { .find_commands_by_prefix(prefix) .into_iter() .map(move |x| Suggestion { - value: String::from_utf8_lossy(&x).to_string(), - description: None, + value: String::from_utf8_lossy(&x.0).to_string(), + description: x.1, span: reedline::Span { start: span.start - offset, end: span.end - offset, diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index 9ba7bf801..13cda3390 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -443,13 +443,14 @@ impl EngineState { None } - pub fn find_commands_by_prefix(&self, name: &[u8]) -> Vec> { + pub fn find_commands_by_prefix(&self, name: &[u8]) -> Vec<(Vec, Option)> { let mut output = vec![]; for scope in self.scope.iter().rev() { for decl in &scope.decls { if decl.0.starts_with(name) { - output.push(decl.0.clone()); + let command = self.get_decl(*decl.1); + output.push((decl.0.clone(), Some(command.usage().to_string()))); } } } @@ -1296,13 +1297,14 @@ impl<'a> StateWorkingSet<'a> { } } - pub fn find_commands_by_prefix(&self, name: &[u8]) -> Vec> { + pub fn find_commands_by_prefix(&self, name: &[u8]) -> Vec<(Vec, Option)> { let mut output = vec![]; for scope in self.delta.scope.iter().rev() { for decl in &scope.decls { if decl.0.starts_with(name) { - output.push(decl.0.clone()); + let command = self.get_decl(*decl.1); + output.push((decl.0.clone(), Some(command.usage().to_string()))); } } }