Check same-string-different-case in did_you_mean (#4991)

This commit is contained in:
Reilly Wood 2022-03-26 23:21:39 -07:00 committed by GitHub
parent ee5064abed
commit 0011f4df56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -360,6 +360,15 @@ impl From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
}
pub fn did_you_mean(possibilities: &[String], tried: &str) -> Option<String> {
// First see if we can find the same string just cased differently
let great_match_index = possibilities
.iter()
.position(|word| word.to_lowercase() == tried.to_lowercase());
if let Some(index) = great_match_index {
return Some(possibilities[index].to_owned());
}
let mut possible_matches: Vec<_> = possibilities
.iter()
.map(|word| {