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 @@ pub fn new(query: &str) -> Self { } } + /// 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 @@ pub fn exclude_import_kind(mut self, import_kind: ImportKind) -> Self { } } -// 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, - name_to_import: &str, + fuzzy_search_string: &str, name_only: bool, ) -> impl Iterator> { 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);