Remove positional from CompleteOptions

This commit is contained in:
Vansh Nath 2025-04-06 21:58:00 +02:00
parent 48347f38bb
commit 6bed42b0cf
No known key found for this signature in database
GPG Key ID: 709BF3EAFB217A96
3 changed files with 14 additions and 16 deletions

View File

@ -124,11 +124,7 @@ impl<T> 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(),
}

View File

@ -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<T: Completer> Completer for CustomCompletion<T> {
{
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
}
}
}
}

View File

@ -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"],