diff options
Diffstat (limited to 'crates/ide_db/src/items_locator.rs')
-rw-r--r-- | crates/ide_db/src/items_locator.rs | 20 |
1 files changed, 13 insertions, 7 deletions
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. | ||
4 | use either::Either; | 5 | use either::Either; |
5 | use hir::{ | 6 | use hir::{ |
6 | import_map::{self, ImportKind}, | 7 | import_map::{self, ImportKind}, |
@@ -16,24 +17,29 @@ use crate::{ | |||
16 | }; | 17 | }; |
17 | use rustc_hash::FxHashSet; | 18 | use rustc_hash::FxHashSet; |
18 | 19 | ||
19 | pub(crate) const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; | 20 | /// A value to use, when uncertain which limit to pick. |
21 | pub 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)] |
23 | pub enum AssocItemSearch { | 25 | pub 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 | ||
29 | pub fn locate_for_name( | 34 | /// Searches for importable items with the given name in the crate and its dependencies. |
35 | pub 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(), |