From a42d419b66b5939b8f285c6221f2bc43859340fc Mon Sep 17 00:00:00 2001 From: Herlon Aguiar Date: Thu, 26 May 2022 02:10:46 +0200 Subject: [PATCH] nu-cli/completions: fix filter for variable completions (#5641) --- .../src/completions/variable_completions.rs | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/nu-cli/src/completions/variable_completions.rs b/crates/nu-cli/src/completions/variable_completions.rs index 1bfd622edf..390f4dc800 100644 --- a/crates/nu-cli/src/completions/variable_completions.rs +++ b/crates/nu-cli/src/completions/variable_completions.rs @@ -70,7 +70,18 @@ impl Completer for VariableCompletion { self.var_context.1.clone().into_iter().skip(1).collect(); if let Some(val) = env_vars.get(&target_var_str) { - return nested_suggestions(val.clone(), nested_levels, current_span); + for suggestion in + nested_suggestions(val.clone(), nested_levels, current_span) + { + if options + .match_algorithm + .matches_u8(suggestion.value.as_bytes(), &prefix) + { + output.push(suggestion); + } + } + + return output; } } else { // No nesting provided, return all env vars @@ -105,7 +116,18 @@ impl Completer for VariableCompletion { end: current_span.end, }, ) { - return nested_suggestions(nuval, self.var_context.1.clone(), current_span); + for suggestion in + nested_suggestions(nuval, self.var_context.1.clone(), current_span) + { + if options + .match_algorithm + .matches_u8(suggestion.value.as_bytes(), &prefix) + { + output.push(suggestion); + } + } + + return output; } } @@ -122,7 +144,18 @@ impl Completer for VariableCompletion { // If the value exists and it's of type Record if let Ok(value) = var { - return nested_suggestions(value, self.var_context.1.clone(), current_span); + for suggestion in + nested_suggestions(value, self.var_context.1.clone(), current_span) + { + if options + .match_algorithm + .matches_u8(suggestion.value.as_bytes(), &prefix) + { + output.push(suggestion); + } + } + + return output; } } }