From 0d8786f5a141b5350d0b942076d906290ad76cd4 Mon Sep 17 00:00:00 2001 From: iff Date: Sat, 23 Nov 2024 21:18:10 +0100 Subject: [PATCH] chore: dynamic linguistic distance --- src/suggestions.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/suggestions.rs b/src/suggestions.rs index 7dd316f..5f4a1a3 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -177,24 +177,30 @@ pub fn suggest_typo(typos: &[String], candidates: Vec) -> String { }; if let Some(suggest) = find_similar(typo, &path_files) { suggestions.push(suggest); - }; + } else { + suggestions.push(typo.to_string()); + } } "file" => { if let Some(suggest) = get_best_match_file(typo) { suggestions.push(suggest); + } else { + suggestions.push(typo.to_string()); } } _ => {} } } else if let Some(suggest) = find_similar(typo, &candidates) { suggestions.push(suggest); + } else { + suggestions.push(typo.to_string()); } } suggestions.join(" ") } pub fn find_similar(typo: &str, candidates: &[String]) -> Option { - let mut min_distance = 10; + let mut min_distance = { std::cmp::max(2, typo.chars().count() / 2 + 1) }; let mut min_distance_index = None; for (i, candidate) in candidates.iter().enumerate() { if candidate.is_empty() {