aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/autoderef.rs1
-rw-r--r--crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs4
-rw-r--r--crates/ide_completion/src/lib.rs4
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs6
-rw-r--r--crates/ide_db/src/items_locator.rs20
5 files changed, 20 insertions, 15 deletions
diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs
index 0b8ac455b..23ab042c1 100644
--- a/crates/hir_ty/src/autoderef.rs
+++ b/crates/hir_ty/src/autoderef.rs
@@ -27,7 +27,6 @@ pub fn autoderef<'a>(
27 krate: Option<CrateId>, 27 krate: Option<CrateId>,
28 ty: InEnvironment<Canonical<Ty>>, 28 ty: InEnvironment<Canonical<Ty>>,
29) -> impl Iterator<Item = Canonical<Ty>> + 'a { 29) -> impl Iterator<Item = Canonical<Ty>> + 'a {
30 // from_chalk
31 let InEnvironment { value: ty, environment } = ty; 30 let InEnvironment { value: ty, environment } = ty;
32 successors(Some(ty), move |ty| { 31 successors(Some(ty), move |ty| {
33 deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() }) 32 deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() })
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 1a98c51ce..2608b56da 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
@@ -65,12 +65,12 @@ pub(crate) fn replace_derive_with_manual_impl(
65 let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; 65 let current_module = ctx.sema.scope(annotated_name.syntax()).module()?;
66 let current_crate = current_module.krate(); 66 let current_crate = current_module.krate();
67 67
68 let found_traits = items_locator::locate_for_name( 68 let found_traits = items_locator::items_with_name(
69 &ctx.sema, 69 &ctx.sema,
70 current_crate, 70 current_crate,
71 NameToImport::Exact(trait_token.text().to_string()), 71 NameToImport::Exact(trait_token.text().to_string()),
72 items_locator::AssocItemSearch::Exclude, 72 items_locator::AssocItemSearch::Exclude,
73 None, 73 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
74 ) 74 )
75 .into_iter() 75 .into_iter()
76 .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { 76 .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs
index c91c98871..9ecd82b06 100644
--- a/crates/ide_completion/src/lib.rs
+++ b/crates/ide_completion/src/lib.rs
@@ -152,12 +152,12 @@ pub fn resolve_completion_edits(
152 let current_module = ctx.sema.scope(position_for_import).module()?; 152 let current_module = ctx.sema.scope(position_for_import).module()?;
153 let current_crate = current_module.krate(); 153 let current_crate = current_module.krate();
154 154
155 let (import_path, item_to_import) = items_locator::locate_for_name( 155 let (import_path, item_to_import) = items_locator::items_with_name(
156 &ctx.sema, 156 &ctx.sema,
157 current_crate, 157 current_crate,
158 NameToImport::Exact(imported_name), 158 NameToImport::Exact(imported_name),
159 items_locator::AssocItemSearch::Include, 159 items_locator::AssocItemSearch::Include,
160 None, 160 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
161 ) 161 )
162 .into_iter() 162 .into_iter()
163 .filter_map(|candidate| { 163 .filter_map(|candidate| {
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs
index ae234eddc..6995c3e19 100644
--- a/crates/ide_db/src/helpers/import_assets.rs
+++ b/crates/ide_db/src/helpers/import_assets.rs
@@ -252,7 +252,7 @@ fn path_applicable_imports(
252 252
253 match &path_candidate.qualifier { 253 match &path_candidate.qualifier {
254 None => { 254 None => {
255 items_locator::locate_for_name( 255 items_locator::items_with_name(
256 sema, 256 sema,
257 current_crate, 257 current_crate,
258 path_candidate.name.clone(), 258 path_candidate.name.clone(),
@@ -271,7 +271,7 @@ fn path_applicable_imports(
271 let unresolved_qualifier = 271 let unresolved_qualifier =
272 path_to_string_stripping_turbo_fish(&first_segment_unresolved.full_qualifier); 272 path_to_string_stripping_turbo_fish(&first_segment_unresolved.full_qualifier);
273 let unresolved_first_segment = first_segment_unresolved.fist_segment.text(); 273 let unresolved_first_segment = first_segment_unresolved.fist_segment.text();
274 items_locator::locate_for_name( 274 items_locator::items_with_name(
275 sema, 275 sema,
276 current_crate, 276 current_crate,
277 path_candidate.name.clone(), 277 path_candidate.name.clone(),
@@ -416,7 +416,7 @@ fn trait_applicable_items(
416 let db = sema.db; 416 let db = sema.db;
417 417
418 let mut required_assoc_items = FxHashSet::default(); 418 let mut required_assoc_items = FxHashSet::default();
419 let trait_candidates = items_locator::locate_for_name( 419 let trait_candidates = items_locator::items_with_name(
420 sema, 420 sema,
421 current_crate, 421 current_crate,
422 trait_candidate.assoc_item_name.clone(), 422 trait_candidate.assoc_item_name.clone(),
diff --git a/crates/ide_db/src/items_locator.rs b/crates/ide_db/src/items_locator.rs
index 088be72c4..518cddd74 100644
--- a/crates/ide_db/src/items_locator.rs
+++ b/crates/ide_db/src/items_locator.rs
@@ -1,6 +1,7 @@
1//! This module contains an import search functionality that is provided to the assists module. 1//! This module has the functionality to search the project and its dependencies for a certain item,
2//! Later, this should be moved away to a separate crate that is accessible from the assists module. 2//! by its name and a few criteria.
3 3//! The main reason for this module to exist is the fact that project's items and dependencies' items
4//! are located in different caches, with different APIs.
4use either::Either; 5use either::Either;
5use hir::{ 6use hir::{
6 import_map::{self, ImportKind}, 7 import_map::{self, ImportKind},
@@ -16,24 +17,29 @@ use crate::{
16}; 17};
17use rustc_hash::FxHashSet; 18use rustc_hash::FxHashSet;
18 19
19pub(crate) const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; 20/// A value to use, when uncertain which limit to pick.
21pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40;
20 22
21/// TODO kb docs here and around + update the module doc 23/// Three possible ways to search for the name in associated and/or other items.
22#[derive(Debug, Clone, Copy)] 24#[derive(Debug, Clone, Copy)]
23pub enum AssocItemSearch { 25pub enum AssocItemSearch {
26 /// Search for the name in both associated and other items.
24 Include, 27 Include,
28 /// Search for the name in other items only.
25 Exclude, 29 Exclude,
30 /// Search for the name in the associated items only.
26 AssocItemsOnly, 31 AssocItemsOnly,
27} 32}
28 33
29pub fn locate_for_name( 34/// Searches for importable items with the given name in the crate and its dependencies.
35pub fn items_with_name(
30 sema: &Semantics<'_, RootDatabase>, 36 sema: &Semantics<'_, RootDatabase>,
31 krate: Crate, 37 krate: Crate,
32 name: NameToImport, 38 name: NameToImport,
33 assoc_item_search: AssocItemSearch, 39 assoc_item_search: AssocItemSearch,
34 limit: Option<usize>, 40 limit: Option<usize>,
35) -> FxHashSet<ItemInNs> { 41) -> FxHashSet<ItemInNs> {
36 let _p = profile::span("locate_for_name").detail(|| { 42 let _p = profile::span("items_with_name").detail(|| {
37 format!( 43 format!(
38 "Name: {} ({:?}), crate: {:?}, limit: {:?}", 44 "Name: {} ({:?}), crate: {:?}, limit: {:?}",
39 name.text(), 45 name.text(),