Rename 'default' option to 'smart'

This commit is contained in:
ysthakur 2024-08-05 19:54:25 -04:00
parent 786a6acb79
commit 617608711c
5 changed files with 11 additions and 11 deletions

View File

@ -320,7 +320,7 @@ pub fn sort_completions<T>(
get_value: fn(&T) -> &str,
) -> Vec<T> {
// Sort items
if options.sort == CompletionSort::Default && options.match_algorithm == MatchAlgorithm::Fuzzy {
if options.sort == CompletionSort::Smart && options.match_algorithm == MatchAlgorithm::Fuzzy {
let mut matcher = SkimMatcherV2::default();
if options.case_sensitive {
matcher = matcher.respect_case();

View File

@ -111,7 +111,7 @@ impl Completer for CustomCompletion {
sort: if should_sort {
CompletionSort::Alphabetical
} else {
CompletionSort::Default
CompletionSort::Smart
},
});
}

View File

@ -788,8 +788,8 @@ fn subcommand_completions(mut subcommand_completer: NuCompleter) {
let prefix = "foo br";
let suggestions = subcommand_completer.complete(prefix, prefix.len());
match_suggestions(
vec!["foo bar".to_string(), "foo aabcrr".to_string()],
suggestions,
&vec!["foo bar".to_string(), "foo aabcrr".to_string()],
&suggestions,
);
let prefix = "foo b";
@ -1290,8 +1290,8 @@ fn sort_fuzzy_completions_in_alphabetical_order(mut fuzzy_alpha_sort_completer:
// Even though "nushell" is a better match, it should come second because
// the completions should be sorted in alphabetical order
match_suggestions(
vec!["custom_completion.nu".into(), "nushell".into()],
suggestions,
&vec!["custom_completion.nu".into(), "nushell".into()],
&suggestions,
);
}

View File

@ -38,7 +38,7 @@ impl ReconstructVal for CompletionAlgorithm {
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default, PartialEq)]
pub enum CompletionSort {
#[default]
Default,
Smart,
Alphabetical,
}
@ -47,9 +47,9 @@ impl FromStr for CompletionSort {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"default" => Ok(Self::Default),
"smart" => Ok(Self::Smart),
"alphabetical" => Ok(Self::Alphabetical),
_ => Err("expected either 'default' or 'alpha'"),
_ => Err("expected either 'smart' or 'alphabetical'"),
}
}
}
@ -57,7 +57,7 @@ impl FromStr for CompletionSort {
impl ReconstructVal for CompletionSort {
fn reconstruct_value(&self, span: Span) -> Value {
let str = match self {
Self::Default => "default",
Self::Smart => "smart",
Self::Alphabetical => "alphabetical",
};
Value::string(str, span)

View File

@ -206,7 +206,7 @@ $env.config = {
quick: true # set this to false to prevent auto-selecting completions when only one remains
partial: true # set this to false to prevent partial filling of the prompt
algorithm: "prefix" # prefix or fuzzy
sort: "default" # "default" (choose based on algorithm) or "alphabetical"
sort: "smart" # "smart" (alphabetical for prefix matching, fuzzy score for fuzzy matching) or "alphabetical"
external: {
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up may be very slow
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options