From 879432452d15d4e9c373a6233a0cd15e22f20ef3 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 22:54:04 +0200 Subject: Docs --- crates/hir_ty/src/autoderef.rs | 1 - .../src/handlers/replace_derive_with_manual_impl.rs | 4 ++-- crates/ide_completion/src/lib.rs | 4 ++-- crates/ide_db/src/helpers/import_assets.rs | 6 +++--- crates/ide_db/src/items_locator.rs | 20 +++++++++++++------- 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>( krate: Option, ty: InEnvironment>, ) -> impl Iterator> + 'a { - // from_chalk let InEnvironment { value: ty, environment } = ty; successors(Some(ty), move |ty| { 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( let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; let current_crate = current_module.krate(); - let found_traits = items_locator::locate_for_name( + let found_traits = items_locator::items_with_name( &ctx.sema, current_crate, NameToImport::Exact(trait_token.text().to_string()), items_locator::AssocItemSearch::Exclude, - None, + Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), ) .into_iter() .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( let current_module = ctx.sema.scope(position_for_import).module()?; let current_crate = current_module.krate(); - let (import_path, item_to_import) = items_locator::locate_for_name( + let (import_path, item_to_import) = items_locator::items_with_name( &ctx.sema, current_crate, NameToImport::Exact(imported_name), items_locator::AssocItemSearch::Include, - None, + Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), ) .into_iter() .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( match &path_candidate.qualifier { None => { - items_locator::locate_for_name( + items_locator::items_with_name( sema, current_crate, path_candidate.name.clone(), @@ -271,7 +271,7 @@ fn path_applicable_imports( let unresolved_qualifier = path_to_string_stripping_turbo_fish(&first_segment_unresolved.full_qualifier); let unresolved_first_segment = first_segment_unresolved.fist_segment.text(); - items_locator::locate_for_name( + items_locator::items_with_name( sema, current_crate, path_candidate.name.clone(), @@ -416,7 +416,7 @@ fn trait_applicable_items( let db = sema.db; let mut required_assoc_items = FxHashSet::default(); - let trait_candidates = items_locator::locate_for_name( + let trait_candidates = items_locator::items_with_name( sema, current_crate, 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 @@ -//! This module contains an import search functionality that is provided to the assists module. -//! Later, this should be moved away to a separate crate that is accessible from the assists module. - +//! This module has the functionality to search the project and its dependencies for a certain item, +//! by its name and a few criteria. +//! The main reason for this module to exist is the fact that project's items and dependencies' items +//! are located in different caches, with different APIs. use either::Either; use hir::{ import_map::{self, ImportKind}, @@ -16,24 +17,29 @@ use crate::{ }; use rustc_hash::FxHashSet; -pub(crate) const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; +/// A value to use, when uncertain which limit to pick. +pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; -/// TODO kb docs here and around + update the module doc +/// Three possible ways to search for the name in associated and/or other items. #[derive(Debug, Clone, Copy)] pub enum AssocItemSearch { + /// Search for the name in both associated and other items. Include, + /// Search for the name in other items only. Exclude, + /// Search for the name in the associated items only. AssocItemsOnly, } -pub fn locate_for_name( +/// Searches for importable items with the given name in the crate and its dependencies. +pub fn items_with_name( sema: &Semantics<'_, RootDatabase>, krate: Crate, name: NameToImport, assoc_item_search: AssocItemSearch, limit: Option, ) -> FxHashSet { - let _p = profile::span("locate_for_name").detail(|| { + let _p = profile::span("items_with_name").detail(|| { format!( "Name: {} ({:?}), crate: {:?}, limit: {:?}", name.text(), -- cgit v1.2.3