Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/import_map.rs')
-rw-r--r--crates/hir-def/src/import_map.rs65
1 files changed, 23 insertions, 42 deletions
diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs
index c2434717e7..9a40d30637 100644
--- a/crates/hir-def/src/import_map.rs
+++ b/crates/hir-def/src/import_map.rs
@@ -295,7 +295,6 @@ pub struct Query {
search_mode: SearchMode,
assoc_mode: AssocSearchMode,
case_sensitive: bool,
- limit: usize,
}
impl Query {
@@ -307,7 +306,6 @@ impl Query {
search_mode: SearchMode::Exact,
assoc_mode: AssocSearchMode::Include,
case_sensitive: false,
- limit: usize::MAX,
}
}
@@ -329,11 +327,6 @@ impl Query {
Self { assoc_mode, ..self }
}
- /// Limits the returned number of items to `limit`.
- pub fn limit(self, limit: usize) -> Self {
- Self { limit, ..self }
- }
-
/// Respect casing of the query string when matching.
pub fn case_sensitive(self) -> Self {
Self { case_sensitive: true, ..self }
@@ -413,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)
})
@@ -424,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
@@ -442,10 +455,6 @@ fn search_maps(
}
});
res.extend(iter.map(TupleExt::head));
-
- if res.len() >= query.limit {
- return res;
- }
}
}
@@ -1015,32 +1024,4 @@ pub mod fmt {
"#]],
);
}
-
- #[test]
- fn search_limit() {
- check_search(
- r#"
- //- /main.rs crate:main deps:dep
- //- /dep.rs crate:dep
- pub mod fmt {
- pub trait Display {
- fn fmt();
- }
- }
- #[macro_export]
- macro_rules! Fmt {
- () => {};
- }
- pub struct Fmt;
-
- pub fn format() {}
- pub fn no() {}
- "#,
- "main",
- Query::new("".to_string()).fuzzy().limit(1),
- expect![[r#"
- dep::fmt::Display (t)
- "#]],
- );
- }
}