about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKirill Bulatov <mail4score@gmail.com>2020-12-28 14:54:31 +0200
committerKirill Bulatov <mail4score@gmail.com>2020-12-28 15:09:39 +0200
commite4c3f753d23752a9fbb01bdf1cd92a8cb1f6681e (patch)
tree3533241d0cc71451350c42d5d48404be7b83e575
parentc4995cfbd5b265c02d3038d72b8a022cde5f7040 (diff)
downloadrust-e4c3f753d23752a9fbb01bdf1cd92a8cb1f6681e.tar.gz
rust-e4c3f753d23752a9fbb01bdf1cd92a8cb1f6681e.zip
Add docs and optimisations
-rw-r--r--crates/completion/src/completions/unqualified_path.rs4
-rw-r--r--crates/hir_def/src/import_map.rs17
-rw-r--r--crates/ide_db/src/imports_locator.rs6
3 files changed, 18 insertions, 9 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index d0984975206..aefbdb16321 100644
--- a/crates/completion/src/completions/unqualified_path.rs
+++ b/crates/completion/src/completions/unqualified_path.rs
@@ -101,8 +101,8 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
 //
 // .Fuzzy search details
 //
-// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only
-// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers.
+// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the names only
+// (i.e. in `HashMap` in the `std::collections::HashMap` path).
 //
 // .Merge Behavior
 //
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index ce25e1c6e9a..34a424c601a 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -238,11 +238,15 @@ pub enum ImportKind {
     BuiltinType,
 }
 
-/// todo kb
+/// A way to match import map contents against the search query.
 #[derive(Debug)]
 pub enum SearchMode {
+    /// Import map entry should strictly match the query string.
     Equals,
+    /// Import map entry should contain the query string.
     Contains,
+    /// Import map entry should contain all letters from the query string,
+    /// in the same order, but not necessary adjacent.
     Fuzzy,
 }
 
@@ -270,11 +274,14 @@ impl Query {
         }
     }
 
+    /// Matches entries' names only, ignoring the rest of
+    /// the qualifier.
+    /// Example: for `std::marker::PhantomData`, the name is `PhantomData`.
     pub fn name_only(self) -> Self {
         Self { name_only: true, ..self }
     }
 
-    /// todo kb
+    /// Specifies the way to search for the entries using the query.
     pub fn search_mode(self, search_mode: SearchMode) -> Self {
         Self { search_mode, ..self }
     }
@@ -296,7 +303,6 @@ impl Query {
     }
 }
 
-// TODO kb: ugly with a special `return true` case and the `enforce_lowercase` one.
 fn contains_query(query: &Query, input_path: &ImportPath, enforce_lowercase: bool) -> bool {
     let mut input = if query.name_only {
         input_path.segments.last().unwrap().to_string()
@@ -378,7 +384,10 @@ pub fn search_dependencies<'a>(
                     Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind),
                     None => true,
                 })
-                .filter(|item| contains_query(&query, &import_map.map[item].path, false));
+                .filter(|item| {
+                    !query.case_sensitive // we've already checked the common importables path case-insensitively
+                        || contains_query(&query, &import_map.map[item].path, false)
+                });
             res.extend(iter);
 
             if res.len() >= query.limit {
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs
index 986cb5b8363..b6355af4bd7 100644
--- a/crates/ide_db/src/imports_locator.rs
+++ b/crates/ide_db/src/imports_locator.rs
@@ -39,18 +39,18 @@ pub fn find_similar_imports<'a>(
     sema: &Semantics<'a, RootDatabase>,
     krate: Crate,
     limit: Option<usize>,
-    name_to_import: &str,
+    fuzzy_search_string: &str,
     name_only: bool,
 ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
     let _p = profile::span("find_similar_imports");
 
     let mut external_query =
-        import_map::Query::new(name_to_import).search_mode(import_map::SearchMode::Fuzzy);
+        import_map::Query::new(fuzzy_search_string).search_mode(import_map::SearchMode::Fuzzy);
     if name_only {
         external_query = external_query.name_only();
     }
 
-    let mut local_query = symbol_index::Query::new(name_to_import.to_string());
+    let mut local_query = symbol_index::Query::new(fuzzy_search_string.to_string());
 
     if let Some(limit) = limit {
         local_query.limit(limit);