mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Docs
This commit is contained in:
parent
a631108d2d
commit
879432452d
5 changed files with 20 additions and 15 deletions
|
@ -27,7 +27,6 @@ pub fn autoderef<'a>(
|
||||||
krate: Option<CrateId>,
|
krate: Option<CrateId>,
|
||||||
ty: InEnvironment<Canonical<Ty>>,
|
ty: InEnvironment<Canonical<Ty>>,
|
||||||
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
|
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
|
||||||
// from_chalk
|
|
||||||
let InEnvironment { value: ty, environment } = ty;
|
let InEnvironment { value: ty, environment } = ty;
|
||||||
successors(Some(ty), move |ty| {
|
successors(Some(ty), move |ty| {
|
||||||
deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() })
|
deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() })
|
||||||
|
|
|
@ -65,12 +65,12 @@ pub(crate) fn replace_derive_with_manual_impl(
|
||||||
let current_module = ctx.sema.scope(annotated_name.syntax()).module()?;
|
let current_module = ctx.sema.scope(annotated_name.syntax()).module()?;
|
||||||
let current_crate = current_module.krate();
|
let current_crate = current_module.krate();
|
||||||
|
|
||||||
let found_traits = items_locator::locate_for_name(
|
let found_traits = items_locator::items_with_name(
|
||||||
&ctx.sema,
|
&ctx.sema,
|
||||||
current_crate,
|
current_crate,
|
||||||
NameToImport::Exact(trait_token.text().to_string()),
|
NameToImport::Exact(trait_token.text().to_string()),
|
||||||
items_locator::AssocItemSearch::Exclude,
|
items_locator::AssocItemSearch::Exclude,
|
||||||
None,
|
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
|
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
|
||||||
|
|
|
@ -152,12 +152,12 @@ pub fn resolve_completion_edits(
|
||||||
let current_module = ctx.sema.scope(position_for_import).module()?;
|
let current_module = ctx.sema.scope(position_for_import).module()?;
|
||||||
let current_crate = current_module.krate();
|
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,
|
&ctx.sema,
|
||||||
current_crate,
|
current_crate,
|
||||||
NameToImport::Exact(imported_name),
|
NameToImport::Exact(imported_name),
|
||||||
items_locator::AssocItemSearch::Include,
|
items_locator::AssocItemSearch::Include,
|
||||||
None,
|
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|candidate| {
|
.filter_map(|candidate| {
|
||||||
|
|
|
@ -252,7 +252,7 @@ fn path_applicable_imports(
|
||||||
|
|
||||||
match &path_candidate.qualifier {
|
match &path_candidate.qualifier {
|
||||||
None => {
|
None => {
|
||||||
items_locator::locate_for_name(
|
items_locator::items_with_name(
|
||||||
sema,
|
sema,
|
||||||
current_crate,
|
current_crate,
|
||||||
path_candidate.name.clone(),
|
path_candidate.name.clone(),
|
||||||
|
@ -271,7 +271,7 @@ fn path_applicable_imports(
|
||||||
let unresolved_qualifier =
|
let unresolved_qualifier =
|
||||||
path_to_string_stripping_turbo_fish(&first_segment_unresolved.full_qualifier);
|
path_to_string_stripping_turbo_fish(&first_segment_unresolved.full_qualifier);
|
||||||
let unresolved_first_segment = first_segment_unresolved.fist_segment.text();
|
let unresolved_first_segment = first_segment_unresolved.fist_segment.text();
|
||||||
items_locator::locate_for_name(
|
items_locator::items_with_name(
|
||||||
sema,
|
sema,
|
||||||
current_crate,
|
current_crate,
|
||||||
path_candidate.name.clone(),
|
path_candidate.name.clone(),
|
||||||
|
@ -416,7 +416,7 @@ fn trait_applicable_items(
|
||||||
let db = sema.db;
|
let db = sema.db;
|
||||||
|
|
||||||
let mut required_assoc_items = FxHashSet::default();
|
let mut required_assoc_items = FxHashSet::default();
|
||||||
let trait_candidates = items_locator::locate_for_name(
|
let trait_candidates = items_locator::items_with_name(
|
||||||
sema,
|
sema,
|
||||||
current_crate,
|
current_crate,
|
||||||
trait_candidate.assoc_item_name.clone(),
|
trait_candidate.assoc_item_name.clone(),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! This module contains an import search functionality that is provided to the assists module.
|
//! This module has the functionality to search the project and its dependencies for a certain item,
|
||||||
//! Later, this should be moved away to a separate crate that is accessible from the assists module.
|
//! 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 either::Either;
|
||||||
use hir::{
|
use hir::{
|
||||||
import_map::{self, ImportKind},
|
import_map::{self, ImportKind},
|
||||||
|
@ -16,24 +17,29 @@ use crate::{
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
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)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum AssocItemSearch {
|
pub enum AssocItemSearch {
|
||||||
|
/// Search for the name in both associated and other items.
|
||||||
Include,
|
Include,
|
||||||
|
/// Search for the name in other items only.
|
||||||
Exclude,
|
Exclude,
|
||||||
|
/// Search for the name in the associated items only.
|
||||||
AssocItemsOnly,
|
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>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: Crate,
|
krate: Crate,
|
||||||
name: NameToImport,
|
name: NameToImport,
|
||||||
assoc_item_search: AssocItemSearch,
|
assoc_item_search: AssocItemSearch,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> FxHashSet<ItemInNs> {
|
) -> FxHashSet<ItemInNs> {
|
||||||
let _p = profile::span("locate_for_name").detail(|| {
|
let _p = profile::span("items_with_name").detail(|| {
|
||||||
format!(
|
format!(
|
||||||
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
|
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
|
||||||
name.text(),
|
name.text(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue