mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Fix symbol_index::Query::search_maps not adhering to case-sensitivity correctly
This commit is contained in:
parent
c3a29e5528
commit
0af780ea3e
4 changed files with 133 additions and 55 deletions
|
@ -406,6 +406,7 @@ fn search_maps(
|
|||
})
|
||||
// we put all entries with the same lowercased name in a row, so stop once we find a
|
||||
// different name in the importables
|
||||
// FIXME: Consider putting a range into the value: u64 as (u32, u32)?
|
||||
.take_while(|&(_, info, _)| {
|
||||
info.name.to_smol_str().as_bytes().eq_ignore_ascii_case(&key)
|
||||
})
|
||||
|
@ -417,13 +418,32 @@ fn search_maps(
|
|||
return true;
|
||||
}
|
||||
let name = info.name.to_smol_str();
|
||||
// FIXME: Deduplicate this from ide-db
|
||||
match query.search_mode {
|
||||
SearchMode::Exact => name == query.query,
|
||||
SearchMode::Prefix => name.starts_with(&query.query),
|
||||
SearchMode::Exact => !query.case_sensitive || name == query.query,
|
||||
SearchMode::Prefix => {
|
||||
query.query.len() <= name.len() && {
|
||||
let prefix = &name[..query.query.len() as usize];
|
||||
if query.case_sensitive {
|
||||
prefix == query.query
|
||||
} else {
|
||||
prefix.eq_ignore_ascii_case(&query.query)
|
||||
}
|
||||
}
|
||||
}
|
||||
SearchMode::Fuzzy => {
|
||||
let mut name = &*name;
|
||||
query.query.chars().all(|query_char| {
|
||||
match name.match_indices(query_char).next() {
|
||||
let m = if query.case_sensitive {
|
||||
name.match_indices(query_char).next()
|
||||
} else {
|
||||
name.match_indices([
|
||||
query_char,
|
||||
query_char.to_ascii_uppercase(),
|
||||
])
|
||||
.next()
|
||||
};
|
||||
match m {
|
||||
Some((index, _)) => {
|
||||
name = &name[index + 1..];
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue