aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-12-28 12:54:31 +0000
committerKirill Bulatov <[email protected]>2020-12-28 13:09:39 +0000
commite4c3f753d23752a9fbb01bdf1cd92a8cb1f6681e (patch)
tree3533241d0cc71451350c42d5d48404be7b83e575 /crates/hir_def
parentc4995cfbd5b265c02d3038d72b8a022cde5f7040 (diff)
Add docs and optimisations
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/import_map.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index ce25e1c6e..34a424c60 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -238,11 +238,15 @@ pub enum ImportKind {
238 BuiltinType, 238 BuiltinType,
239} 239}
240 240
241/// todo kb 241/// A way to match import map contents against the search query.
242#[derive(Debug)] 242#[derive(Debug)]
243pub enum SearchMode { 243pub enum SearchMode {
244 /// Import map entry should strictly match the query string.
244 Equals, 245 Equals,
246 /// Import map entry should contain the query string.
245 Contains, 247 Contains,
248 /// Import map entry should contain all letters from the query string,
249 /// in the same order, but not necessary adjacent.
246 Fuzzy, 250 Fuzzy,
247} 251}
248 252
@@ -270,11 +274,14 @@ impl Query {
270 } 274 }
271 } 275 }
272 276
277 /// Matches entries' names only, ignoring the rest of
278 /// the qualifier.
279 /// Example: for `std::marker::PhantomData`, the name is `PhantomData`.
273 pub fn name_only(self) -> Self { 280 pub fn name_only(self) -> Self {
274 Self { name_only: true, ..self } 281 Self { name_only: true, ..self }
275 } 282 }
276 283
277 /// todo kb 284 /// Specifies the way to search for the entries using the query.
278 pub fn search_mode(self, search_mode: SearchMode) -> Self { 285 pub fn search_mode(self, search_mode: SearchMode) -> Self {
279 Self { search_mode, ..self } 286 Self { search_mode, ..self }
280 } 287 }
@@ -296,7 +303,6 @@ impl Query {
296 } 303 }
297} 304}
298 305
299// TODO kb: ugly with a special `return true` case and the `enforce_lowercase` one.
300fn contains_query(query: &Query, input_path: &ImportPath, enforce_lowercase: bool) -> bool { 306fn contains_query(query: &Query, input_path: &ImportPath, enforce_lowercase: bool) -> bool {
301 let mut input = if query.name_only { 307 let mut input = if query.name_only {
302 input_path.segments.last().unwrap().to_string() 308 input_path.segments.last().unwrap().to_string()
@@ -378,7 +384,10 @@ pub fn search_dependencies<'a>(
378 Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), 384 Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind),
379 None => true, 385 None => true,
380 }) 386 })
381 .filter(|item| contains_query(&query, &import_map.map[item].path, false)); 387 .filter(|item| {
388 !query.case_sensitive // we've already checked the common importables path case-insensitively
389 || contains_query(&query, &import_map.map[item].path, false)
390 });
382 res.extend(iter); 391 res.extend(iter);
383 392
384 if res.len() >= query.limit { 393 if res.len() >= query.limit {