Merge e1b856e9f0
into ca8eb856e8
This commit is contained in:
commit
af4d14b0c7
|
@ -24,6 +24,12 @@ pub enum MatchAlgorithm {
|
|||
/// Example:
|
||||
/// "git checkout" is matched by "gco"
|
||||
Fuzzy,
|
||||
|
||||
/// Only show suggestions which contain the substring starting at any place
|
||||
///
|
||||
/// Example:
|
||||
/// "git checkout" is matched by "check"
|
||||
Substring
|
||||
}
|
||||
|
||||
impl MatchAlgorithm {
|
||||
|
@ -37,6 +43,7 @@ impl MatchAlgorithm {
|
|||
let matcher = SkimMatcherV2::default();
|
||||
matcher.fuzzy_match(haystack, needle).is_some()
|
||||
}
|
||||
MatchAlgorithm::Substring => haystack.contains(needle),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +58,7 @@ impl MatchAlgorithm {
|
|||
let matcher = SkimMatcherV2::default();
|
||||
matcher.fuzzy_match(&haystack_str, &needle_str).is_some()
|
||||
}
|
||||
MatchAlgorithm::Substring => haystack.windows(needle.len()).any(|window| window == needle),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +68,7 @@ impl From<CompletionAlgorithm> for MatchAlgorithm {
|
|||
match value {
|
||||
CompletionAlgorithm::Prefix => MatchAlgorithm::Prefix,
|
||||
CompletionAlgorithm::Fuzzy => MatchAlgorithm::Fuzzy,
|
||||
CompletionAlgorithm::Substring => MatchAlgorithm::Substring,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +80,7 @@ impl TryFrom<String> for MatchAlgorithm {
|
|||
match value.as_str() {
|
||||
"prefix" => Ok(Self::Prefix),
|
||||
"fuzzy" => Ok(Self::Fuzzy),
|
||||
"substring" => Ok(Self::Substring),
|
||||
_ => Err(InvalidMatchAlgorithm::Unknown),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ fn filter(
|
|||
}
|
||||
}
|
||||
},
|
||||
MatchAlgorithm::Fuzzy => options
|
||||
MatchAlgorithm::Fuzzy | MatchAlgorithm::Substring => options
|
||||
.match_algorithm
|
||||
.matches_u8(it.suggestion.value.as_bytes(), prefix),
|
||||
})
|
||||
|
|
|
@ -11,6 +11,7 @@ pub enum CompletionAlgorithm {
|
|||
#[default]
|
||||
Prefix,
|
||||
Fuzzy,
|
||||
Substring,
|
||||
}
|
||||
|
||||
impl FromStr for CompletionAlgorithm {
|
||||
|
@ -20,6 +21,7 @@ impl FromStr for CompletionAlgorithm {
|
|||
match s.to_ascii_lowercase().as_str() {
|
||||
"prefix" => Ok(Self::Prefix),
|
||||
"fuzzy" => Ok(Self::Fuzzy),
|
||||
"substring" => Ok(Self::Substring),
|
||||
_ => Err("expected either 'prefix' or 'fuzzy'"),
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +32,7 @@ impl ReconstructVal for CompletionAlgorithm {
|
|||
let str = match self {
|
||||
CompletionAlgorithm::Prefix => "prefix",
|
||||
CompletionAlgorithm::Fuzzy => "fuzzy",
|
||||
CompletionAlgorithm::Substring => "substring",
|
||||
};
|
||||
Value::string(str, span)
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ $env.config = {
|
|||
case_sensitive: false # set to true to enable case-sensitive completions
|
||||
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
|
||||
algorithm: "prefix" # prefix or fuzzy or substring
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user