This commit is contained in:
Kirill Bulatov 2021-03-20 22:54:04 +02:00
parent a631108d2d
commit 879432452d
5 changed files with 20 additions and 15 deletions

View File

@ -27,7 +27,6 @@ pub fn autoderef<'a>(
krate: Option<CrateId>,
ty: InEnvironment<Canonical<Ty>>,
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
// from_chalk
let InEnvironment { value: ty, environment } = ty;
successors(Some(ty), move |ty| {
deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() })

View File

@ -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()?) {

View File

@ -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| {

View File

@ -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(),

View File

@ -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 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<usize>,
) -> FxHashSet<ItemInNs> {
let _p = profile::span("locate_for_name").detail(|| {
let _p = profile::span("items_with_name").detail(|| {
format!(
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
name.text(),