parent
00e9dabe82
commit
bdee5e7995
|
@ -875,11 +875,12 @@ fn suggest_neighbor<'a>(
|
||||||
items: impl Iterator<Item = &'a String>,
|
items: impl Iterator<Item = &'a String>,
|
||||||
default: &'a str,
|
default: &'a str,
|
||||||
) -> String {
|
) -> String {
|
||||||
|
let threshold = (name.len() as f64).sqrt().round() as usize;
|
||||||
items
|
items
|
||||||
.map(|s| (s, levenshtein::distance(name, s)))
|
.map(|s| (s, levenshtein::distance(name, s)))
|
||||||
.min_by(|(_, a), (_, b)| a.cmp(b))
|
.min_by(|(_, a), (_, b)| a.cmp(b))
|
||||||
.and_then(|(suggestion, distance)| {
|
.and_then(|(suggestion, distance)| {
|
||||||
if distance <= 4 {
|
if distance <= threshold {
|
||||||
Some(format!("Did you mean '{}'?", suggestion.yellow()))
|
Some(format!("Did you mean '{}'?", suggestion.yellow()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in New Issue