aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-03-20 20:54:04 +0000
committerKirill Bulatov <[email protected]>2021-03-20 20:55:34 +0000
commit879432452d15d4e9c373a6233a0cd15e22f20ef3 (patch)
tree918eb815d2da4758d00dfac387b805de6a771c11 /crates/ide_db
parenta631108d2dd0596b079b59efa37b1af00d7555db (diff)
Docs
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs6
-rw-r--r--crates/ide_db/src/items_locator.rs20
2 files changed, 16 insertions, 10 deletions
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(),