mirror of
https://github.com/nushell/nushell.git
synced 2025-06-12 13:06:49 +02:00
Remove positional from CompleteOptions
This commit is contained in:
parent
48347f38bb
commit
6bed42b0cf
@ -124,11 +124,7 @@ impl<T> NuMatcher<'_, T> {
|
|||||||
} else {
|
} else {
|
||||||
Cow::Owned(haystack.to_folded_case())
|
Cow::Owned(haystack.to_folded_case())
|
||||||
};
|
};
|
||||||
let matches = if self.options.positional {
|
let matches = haystack_folded.starts_with(self.needle.as_str());
|
||||||
haystack_folded.starts_with(self.needle.as_str())
|
|
||||||
} else {
|
|
||||||
haystack_folded.contains(self.needle.as_str())
|
|
||||||
};
|
|
||||||
if matches {
|
if matches {
|
||||||
if let Some(item) = item {
|
if let Some(item) = item {
|
||||||
items.push((haystack.to_string(), item));
|
items.push((haystack.to_string(), item));
|
||||||
@ -282,7 +278,6 @@ impl std::error::Error for InvalidMatchAlgorithm {}
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CompletionOptions {
|
pub struct CompletionOptions {
|
||||||
pub case_sensitive: bool,
|
pub case_sensitive: bool,
|
||||||
pub positional: bool,
|
|
||||||
pub match_algorithm: MatchAlgorithm,
|
pub match_algorithm: MatchAlgorithm,
|
||||||
pub sort: CompletionSort,
|
pub sort: CompletionSort,
|
||||||
}
|
}
|
||||||
@ -291,7 +286,6 @@ impl Default for CompletionOptions {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
case_sensitive: true,
|
case_sensitive: true,
|
||||||
positional: true,
|
|
||||||
match_algorithm: MatchAlgorithm::Prefix,
|
match_algorithm: MatchAlgorithm::Prefix,
|
||||||
sort: Default::default(),
|
sort: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::completions::{
|
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_engine::eval_call;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
@ -102,18 +103,22 @@ impl<T: Completer> Completer for CustomCompletion<T> {
|
|||||||
{
|
{
|
||||||
completion_options.case_sensitive = case_sensitive;
|
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
|
if let Some(algorithm) = options
|
||||||
.get("completion_algorithm")
|
.get("completion_algorithm")
|
||||||
.and_then(|option| option.coerce_string().ok())
|
.and_then(|option| option.coerce_string().ok())
|
||||||
.and_then(|option| option.try_into().ok())
|
.and_then(|option| option.try_into().ok())
|
||||||
{
|
{
|
||||||
completion_options.match_algorithm = algorithm;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +228,7 @@ fn customcompletions_override_options() {
|
|||||||
let mut completer = custom_completer_with_options(
|
let mut completer = custom_completer_with_options(
|
||||||
r#"$env.config.completions.algorithm = "fuzzy"
|
r#"$env.config.completions.algorithm = "fuzzy"
|
||||||
$env.config.completions.case_sensitive = false"#,
|
$env.config.completions.case_sensitive = false"#,
|
||||||
r#"completion_algorithm: "prefix",
|
r#"completion_algorithm: "substring",
|
||||||
positional: false,
|
|
||||||
case_sensitive: true,
|
case_sensitive: true,
|
||||||
sort: true"#,
|
sort: true"#,
|
||||||
&["Foo Abcdef", "Abcdef", "Acd Bar"],
|
&["Foo Abcdef", "Abcdef", "Acd Bar"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user