aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs1
-rw-r--r--crates/ide_completion/src/lib.rs1
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs3
-rw-r--r--crates/ide_db/src/items_locator.rs28
4 files changed, 12 insertions, 21 deletions
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
index 2608b56da..4f0ef52ca 100644
--- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -72,7 +72,6 @@ pub(crate) fn replace_derive_with_manual_impl(
72 items_locator::AssocItemSearch::Exclude, 72 items_locator::AssocItemSearch::Exclude,
73 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), 73 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
74 ) 74 )
75 .into_iter()
76 .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { 75 .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
77 ModuleDef::Trait(trait_) => Some(trait_), 76 ModuleDef::Trait(trait_) => Some(trait_),
78 _ => None, 77 _ => None,
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs
index 87cddb98e..5ac1cb48d 100644
--- a/crates/ide_completion/src/lib.rs
+++ b/crates/ide_completion/src/lib.rs
@@ -161,7 +161,6 @@ pub fn resolve_completion_edits(
161 items_locator::AssocItemSearch::Include, 161 items_locator::AssocItemSearch::Include,
162 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), 162 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
163 ) 163 )
164 .into_iter()
165 .filter_map(|candidate| { 164 .filter_map(|candidate| {
166 current_module 165 current_module
167 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind) 166 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs
index 0da7a1a9d..1881c746f 100644
--- a/crates/ide_db/src/helpers/import_assets.rs
+++ b/crates/ide_db/src/helpers/import_assets.rs
@@ -267,7 +267,6 @@ fn path_applicable_imports(
267 AssocItemSearch::Exclude, 267 AssocItemSearch::Exclude,
268 Some(DEFAULT_QUERY_SEARCH_LIMIT), 268 Some(DEFAULT_QUERY_SEARCH_LIMIT),
269 ) 269 )
270 .into_iter()
271 .filter_map(|item| { 270 .filter_map(|item| {
272 let mod_path = mod_path(item)?; 271 let mod_path = mod_path(item)?;
273 Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path))) 272 Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
@@ -285,7 +284,6 @@ fn path_applicable_imports(
285 AssocItemSearch::Include, 284 AssocItemSearch::Include,
286 Some(DEFAULT_QUERY_SEARCH_LIMIT), 285 Some(DEFAULT_QUERY_SEARCH_LIMIT),
287 ) 286 )
288 .into_iter()
289 .filter_map(|item| { 287 .filter_map(|item| {
290 import_for_item( 288 import_for_item(
291 sema.db, 289 sema.db,
@@ -430,7 +428,6 @@ fn trait_applicable_items(
430 AssocItemSearch::AssocItemsOnly, 428 AssocItemSearch::AssocItemsOnly,
431 Some(DEFAULT_QUERY_SEARCH_LIMIT), 429 Some(DEFAULT_QUERY_SEARCH_LIMIT),
432 ) 430 )
433 .into_iter()
434 .filter_map(|input| item_as_assoc(db, input)) 431 .filter_map(|input| item_as_assoc(db, input))
435 .filter_map(|assoc| { 432 .filter_map(|assoc| {
436 let assoc_item_trait = assoc.containing_trait(db)?; 433 let assoc_item_trait = assoc.containing_trait(db)?;
diff --git a/crates/ide_db/src/items_locator.rs b/crates/ide_db/src/items_locator.rs
index b9d5852e2..9af94b86c 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,13 +31,13 @@ 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: {:?}, limit: {:?}",
@@ -94,13 +93,13 @@ pub fn items_with_name(
94 find_items(sema, krate, assoc_item_search, local_query, external_query) 93 find_items(sema, krate, assoc_item_search, local_query, external_query)
95} 94}
96 95
97fn find_items( 96fn find_items<'a>(
98 sema: &Semantics<'_, RootDatabase>, 97 sema: &'a Semantics<'_, RootDatabase>,
99 krate: Crate, 98 krate: Crate,
100 assoc_item_search: AssocItemSearch, 99 assoc_item_search: AssocItemSearch,
101 local_query: symbol_index::Query, 100 local_query: symbol_index::Query,
102 external_query: import_map::Query, 101 external_query: import_map::Query,
103) -> FxHashSet<ItemInNs> { 102) -> impl Iterator<Item = ItemInNs> + 'a {
104 let _p = profile::span("find_items"); 103 let _p = profile::span("find_items");
105 let db = sema.db; 104 let db = sema.db;
106 105
@@ -115,21 +114,18 @@ fn find_items(
115 // Query the local crate using the symbol index. 114 // Query the local crate using the symbol index.
116 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)
117 .into_iter() 116 .into_iter()
118 .filter_map(|local_candidate| get_name_definition(sema, &local_candidate)) 117 .filter_map(move |local_candidate| get_name_definition(sema, &local_candidate))
119 .filter_map(|name_definition_to_import| match name_definition_to_import { 118 .filter_map(|name_definition_to_import| match name_definition_to_import {
120 Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)), 119 Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)),
121 Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)), 120 Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)),
122 _ => None, 121 _ => None,
123 }); 122 });
124 123
125 external_importables 124 external_importables.chain(local_results).filter(move |&item| match assoc_item_search {
126 .chain(local_results) 125 AssocItemSearch::Include => true,
127 .filter(move |&item| match assoc_item_search { 126 AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
128 AssocItemSearch::Include => true, 127 AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
129 AssocItemSearch::Exclude => !is_assoc_item(item, sema.db), 128 })
130 AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
131 })
132 .collect()
133} 129}
134 130
135fn get_name_definition( 131fn get_name_definition(