diff --git a/crates/nu-cli/src/completions/completion_options.rs b/crates/nu-cli/src/completions/completion_options.rs index 97775e177d..2972a9c620 100644 --- a/crates/nu-cli/src/completions/completion_options.rs +++ b/crates/nu-cli/src/completions/completion_options.rs @@ -124,11 +124,7 @@ impl NuMatcher<'_, T> { } else { Cow::Owned(haystack.to_folded_case()) }; - let matches = if self.options.positional { - haystack_folded.starts_with(self.needle.as_str()) - } else { - haystack_folded.contains(self.needle.as_str()) - }; + let matches = haystack_folded.starts_with(self.needle.as_str()); if matches { if let Some(item) = item { items.push((haystack.to_string(), item)); @@ -282,7 +278,6 @@ impl std::error::Error for InvalidMatchAlgorithm {} #[derive(Clone)] pub struct CompletionOptions { pub case_sensitive: bool, - pub positional: bool, pub match_algorithm: MatchAlgorithm, pub sort: CompletionSort, } @@ -291,7 +286,6 @@ impl Default for CompletionOptions { fn default() -> Self { Self { case_sensitive: true, - positional: true, match_algorithm: MatchAlgorithm::Prefix, sort: Default::default(), } diff --git a/crates/nu-cli/src/completions/custom_completions.rs b/crates/nu-cli/src/completions/custom_completions.rs index 191a80b5ee..63a4312ee8 100644 --- a/crates/nu-cli/src/completions/custom_completions.rs +++ b/crates/nu-cli/src/completions/custom_completions.rs @@ -1,5 +1,6 @@ use crate::completions::{ - completer::map_value_completions, Completer, CompletionOptions, SemanticSuggestion, + completer::map_value_completions, Completer, CompletionOptions, MatchAlgorithm, + SemanticSuggestion, }; use nu_engine::eval_call; use nu_protocol::{ @@ -102,18 +103,22 @@ impl Completer for CustomCompletion { { completion_options.case_sensitive = case_sensitive; } - if let Some(positional) = - options.get("positional").and_then(|val| val.as_bool().ok()) - { - log::warn!("Use of the positional option is deprecated. Use the substring match algorithm instead."); - completion_options.positional = positional; - } if let Some(algorithm) = options .get("completion_algorithm") .and_then(|option| option.coerce_string().ok()) .and_then(|option| option.try_into().ok()) { completion_options.match_algorithm = algorithm; + if let Some(positional) = + options.get("positional").and_then(|val| val.as_bool().ok()) + { + if !positional + && completion_options.match_algorithm == MatchAlgorithm::Prefix + { + log::warn!("Use of the positional option is deprecated. Use the substring match algorithm instead."); + completion_options.match_algorithm = MatchAlgorithm::Substring + } + } } } diff --git a/crates/nu-cli/tests/completions/mod.rs b/crates/nu-cli/tests/completions/mod.rs index 9792f2b19b..eb8de0778c 100644 --- a/crates/nu-cli/tests/completions/mod.rs +++ b/crates/nu-cli/tests/completions/mod.rs @@ -228,8 +228,7 @@ fn customcompletions_override_options() { let mut completer = custom_completer_with_options( r#"$env.config.completions.algorithm = "fuzzy" $env.config.completions.case_sensitive = false"#, - r#"completion_algorithm: "prefix", - positional: false, + r#"completion_algorithm: "substring", case_sensitive: true, sort: true"#, &["Foo Abcdef", "Abcdef", "Acd Bar"],