Skip to content

Commit 8794324

Browse files
Docs
1 parent a631108 commit 8794324

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

crates/hir_ty/src/autoderef.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub fn autoderef<'a>(
2727
krate: Option<CrateId>,
2828
ty: InEnvironment<Canonical<Ty>>,
2929
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
30-
// from_chalk
3130
let InEnvironment { value: ty, environment } = ty;
3231
successors(Some(ty), move |ty| {
3332
deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() })

crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ pub(crate) fn replace_derive_with_manual_impl(
6565
let current_module = ctx.sema.scope(annotated_name.syntax()).module()?;
6666
let current_crate = current_module.krate();
6767

68-
let found_traits = items_locator::locate_for_name(
68+
let found_traits = items_locator::items_with_name(
6969
&ctx.sema,
7070
current_crate,
7171
NameToImport::Exact(trait_token.text().to_string()),
7272
items_locator::AssocItemSearch::Exclude,
73-
None,
73+
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
7474
)
7575
.into_iter()
7676
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {

crates/ide_completion/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ pub fn resolve_completion_edits(
152152
let current_module = ctx.sema.scope(position_for_import).module()?;
153153
let current_crate = current_module.krate();
154154

155-
let (import_path, item_to_import) = items_locator::locate_for_name(
155+
let (import_path, item_to_import) = items_locator::items_with_name(
156156
&ctx.sema,
157157
current_crate,
158158
NameToImport::Exact(imported_name),
159159
items_locator::AssocItemSearch::Include,
160-
None,
160+
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
161161
)
162162
.into_iter()
163163
.filter_map(|candidate| {

crates/ide_db/src/helpers/import_assets.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn path_applicable_imports(
252252

253253
match &path_candidate.qualifier {
254254
None => {
255-
items_locator::locate_for_name(
255+
items_locator::items_with_name(
256256
sema,
257257
current_crate,
258258
path_candidate.name.clone(),
@@ -271,7 +271,7 @@ fn path_applicable_imports(
271271
let unresolved_qualifier =
272272
path_to_string_stripping_turbo_fish(&first_segment_unresolved.full_qualifier);
273273
let unresolved_first_segment = first_segment_unresolved.fist_segment.text();
274-
items_locator::locate_for_name(
274+
items_locator::items_with_name(
275275
sema,
276276
current_crate,
277277
path_candidate.name.clone(),
@@ -416,7 +416,7 @@ fn trait_applicable_items(
416416
let db = sema.db;
417417

418418
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(
420420
sema,
421421
current_crate,
422422
trait_candidate.assoc_item_name.clone(),

crates/ide_db/src/items_locator.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
//! This module contains an import search functionality that is provided to the assists module.
2-
//! Later, this should be moved away to a separate crate that is accessible from the assists module.
3-
1+
//! This module has the functionality to search the project and its dependencies for a certain item,
2+
//! by its name and a few criteria.
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.
45
use either::Either;
56
use hir::{
67
import_map::{self, ImportKind},
@@ -16,24 +17,29 @@ use crate::{
1617
};
1718
use rustc_hash::FxHashSet;
1819

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;
2022

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.
2224
#[derive(Debug, Clone, Copy)]
2325
pub enum AssocItemSearch {
26+
/// Search for the name in both associated and other items.
2427
Include,
28+
/// Search for the name in other items only.
2529
Exclude,
30+
/// Search for the name in the associated items only.
2631
AssocItemsOnly,
2732
}
2833

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(
3036
sema: &Semantics<'_, RootDatabase>,
3137
krate: Crate,
3238
name: NameToImport,
3339
assoc_item_search: AssocItemSearch,
3440
limit: Option<usize>,
3541
) -> FxHashSet<ItemInNs> {
36-
let _p = profile::span("locate_for_name").detail(|| {
42+
let _p = profile::span("items_with_name").detail(|| {
3743
format!(
3844
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
3945
name.text(),

0 commit comments

Comments
 (0)