diff options
author | Kirill Bulatov <[email protected]> | 2020-12-28 12:54:31 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-12-28 13:09:39 +0000 |
commit | e4c3f753d23752a9fbb01bdf1cd92a8cb1f6681e (patch) | |
tree | 3533241d0cc71451350c42d5d48404be7b83e575 | |
parent | c4995cfbd5b265c02d3038d72b8a022cde5f7040 (diff) |
Add docs and optimisations
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/import_map.rs | 17 | ||||
-rw-r--r-- | crates/ide_db/src/imports_locator.rs | 6 |
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 d09849752..aefbdb163 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 | |||
101 | // | 101 | // |
102 | // .Fuzzy search details | 102 | // .Fuzzy search details |
103 | // | 103 | // |
104 | // To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only | 104 | // To avoid an excessive amount of the results returned, completion input is checked for inclusion in the names only |
105 | // (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers. | 105 | // (i.e. in `HashMap` in the `std::collections::HashMap` path). |
106 | // | 106 | // |
107 | // .Merge Behavior | 107 | // .Merge Behavior |
108 | // | 108 | // |
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)] |
243 | pub enum SearchMode { | 243 | pub 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. | ||
300 | fn contains_query(query: &Query, input_path: &ImportPath, enforce_lowercase: bool) -> bool { | 306 | fn 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 { |
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index 986cb5b83..b6355af4b 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>( | |||
39 | sema: &Semantics<'a, RootDatabase>, | 39 | sema: &Semantics<'a, RootDatabase>, |
40 | krate: Crate, | 40 | krate: Crate, |
41 | limit: Option<usize>, | 41 | limit: Option<usize>, |
42 | name_to_import: &str, | 42 | fuzzy_search_string: &str, |
43 | name_only: bool, | 43 | name_only: bool, |
44 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { | 44 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { |
45 | let _p = profile::span("find_similar_imports"); | 45 | let _p = profile::span("find_similar_imports"); |
46 | 46 | ||
47 | let mut external_query = | 47 | let mut external_query = |
48 | import_map::Query::new(name_to_import).search_mode(import_map::SearchMode::Fuzzy); | 48 | import_map::Query::new(fuzzy_search_string).search_mode(import_map::SearchMode::Fuzzy); |
49 | if name_only { | 49 | if name_only { |
50 | external_query = external_query.name_only(); | 50 | external_query = external_query.name_only(); |
51 | } | 51 | } |
52 | 52 | ||
53 | let mut local_query = symbol_index::Query::new(name_to_import.to_string()); | 53 | let mut local_query = symbol_index::Query::new(fuzzy_search_string.to_string()); |
54 | 54 | ||
55 | if let Some(limit) = limit { | 55 | if let Some(limit) = limit { |
56 | local_query.limit(limit); | 56 | local_query.limit(limit); |