aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/items_locator.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db/src/items_locator.rs')
-rw-r--r--crates/ide_db/src/items_locator.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/crates/ide_db/src/items_locator.rs b/crates/ide_db/src/items_locator.rs
index 518cddd74..ef796b6f7 100644
--- a/crates/ide_db/src/items_locator.rs
+++ b/crates/ide_db/src/items_locator.rs
@@ -15,7 +15,6 @@ use crate::{
15 symbol_index::{self, FileSymbol}, 15 symbol_index::{self, FileSymbol},
16 RootDatabase, 16 RootDatabase,
17}; 17};
18use rustc_hash::FxHashSet;
19 18
20/// A value to use, when uncertain which limit to pick. 19/// A value to use, when uncertain which limit to pick.
21pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; 20pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40;
@@ -32,16 +31,16 @@ pub enum AssocItemSearch {
32} 31}
33 32
34/// Searches for importable items with the given name in the crate and its dependencies. 33/// Searches for importable items with the given name in the crate and its dependencies.
35pub fn items_with_name( 34pub fn items_with_name<'a>(
36 sema: &Semantics<'_, RootDatabase>, 35 sema: &'a Semantics<'_, RootDatabase>,
37 krate: Crate, 36 krate: Crate,
38 name: NameToImport, 37 name: NameToImport,
39 assoc_item_search: AssocItemSearch, 38 assoc_item_search: AssocItemSearch,
40 limit: Option<usize>, 39 limit: Option<usize>,
41) -> FxHashSet<ItemInNs> { 40) -> impl Iterator<Item = ItemInNs> + 'a {
42 let _p = profile::span("items_with_name").detail(|| { 41 let _p = profile::span("items_with_name").detail(|| {
43 format!( 42 format!(
44 "Name: {} ({:?}), crate: {:?}, limit: {:?}", 43 "Name: {}, crate: {:?}, assoc items: {:?}, limit: {:?}",
45 name.text(), 44 name.text(),
46 assoc_item_search, 45 assoc_item_search,
47 krate.display_name(sema.db).map(|name| name.to_string()), 46 krate.display_name(sema.db).map(|name| name.to_string()),
@@ -62,6 +61,8 @@ pub fn items_with_name(
62 (local_query, external_query) 61 (local_query, external_query)
63 } 62 }
64 NameToImport::Fuzzy(fuzzy_search_string) => { 63 NameToImport::Fuzzy(fuzzy_search_string) => {
64 let mut local_query = symbol_index::Query::new(fuzzy_search_string.clone());
65
65 let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) 66 let mut external_query = import_map::Query::new(fuzzy_search_string.clone())
66 .search_mode(import_map::SearchMode::Fuzzy) 67 .search_mode(import_map::SearchMode::Fuzzy)
67 .name_only(); 68 .name_only();
@@ -75,7 +76,12 @@ pub fn items_with_name(
75 } 76 }
76 } 77 }
77 78
78 (symbol_index::Query::new(fuzzy_search_string), external_query) 79 if fuzzy_search_string.to_lowercase() != fuzzy_search_string {
80 local_query.case_sensitive();
81 external_query = external_query.case_sensitive();
82 }
83
84 (local_query, external_query)
79 } 85 }
80 }; 86 };
81 87
@@ -87,13 +93,13 @@ pub fn items_with_name(
87 find_items(sema, krate, assoc_item_search, local_query, external_query) 93 find_items(sema, krate, assoc_item_search, local_query, external_query)
88} 94}
89 95
90fn find_items( 96fn find_items<'a>(
91 sema: &Semantics<'_, RootDatabase>, 97 sema: &'a Semantics<'_, RootDatabase>,
92 krate: Crate, 98 krate: Crate,
93 assoc_item_search: AssocItemSearch, 99 assoc_item_search: AssocItemSearch,
94 local_query: symbol_index::Query, 100 local_query: symbol_index::Query,
95 external_query: import_map::Query, 101 external_query: import_map::Query,
96) -> FxHashSet<ItemInNs> { 102) -> impl Iterator<Item = ItemInNs> + 'a {
97 let _p = profile::span("find_items"); 103 let _p = profile::span("find_items");
98 let db = sema.db; 104 let db = sema.db;
99 105
@@ -108,21 +114,18 @@ fn find_items(
108 // Query the local crate using the symbol index. 114 // Query the local crate using the symbol index.
109 let local_results = symbol_index::crate_symbols(db, krate.into(), local_query) 115 let local_results = symbol_index::crate_symbols(db, krate.into(), local_query)
110 .into_iter() 116 .into_iter()
111 .filter_map(|local_candidate| get_name_definition(sema, &local_candidate)) 117 .filter_map(move |local_candidate| get_name_definition(sema, &local_candidate))
112 .filter_map(|name_definition_to_import| match name_definition_to_import { 118 .filter_map(|name_definition_to_import| match name_definition_to_import {
113 Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)), 119 Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)),
114 Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)), 120 Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)),
115 _ => None, 121 _ => None,
116 }); 122 });
117 123
118 external_importables 124 external_importables.chain(local_results).filter(move |&item| match assoc_item_search {
119 .chain(local_results) 125 AssocItemSearch::Include => true,
120 .filter(move |&item| match assoc_item_search { 126 AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
121 AssocItemSearch::Include => true, 127 AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
122 AssocItemSearch::Exclude => !is_assoc_item(item, sema.db), 128 })
123 AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
124 })
125 .collect()
126} 129}
127 130
128fn get_name_definition( 131fn get_name_definition(