mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Record import aliases in symbol index
This commit is contained in:
parent
637f496a81
commit
eb6244c5f9
10 changed files with 360 additions and 18 deletions
|
@ -4,6 +4,7 @@ use hir_def::{
|
|||
attr::{AttrsWithOwner, Documentation},
|
||||
item_scope::ItemInNs,
|
||||
path::{ModPath, Path},
|
||||
per_ns::Namespace,
|
||||
resolver::{HasResolver, Resolver, TypeNs},
|
||||
AssocItemId, AttrDefId, GenericParamId, ModuleDefId,
|
||||
};
|
||||
|
@ -28,13 +29,6 @@ pub trait HasAttrs {
|
|||
) -> Option<DocLinkDef>;
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
|
||||
pub enum Namespace {
|
||||
Types,
|
||||
Values,
|
||||
Macros,
|
||||
}
|
||||
|
||||
/// Subset of `ide_db::Definition` that doc links can resolve to.
|
||||
pub enum DocLinkDef {
|
||||
ModuleDef(ModuleDef),
|
||||
|
|
|
@ -88,7 +88,7 @@ use triomphe::Arc;
|
|||
use crate::db::{DefDatabase, HirDatabase};
|
||||
|
||||
pub use crate::{
|
||||
attrs::{DocLinkDef, HasAttrs, Namespace},
|
||||
attrs::{DocLinkDef, HasAttrs},
|
||||
diagnostics::{
|
||||
AnyDiagnostic, BreakOutsideOfLoop, CaseType, ExpectedFunction, InactiveCode,
|
||||
IncoherentImpl, IncorrectCase, InvalidDeriveTarget, MacroDefError, MacroError,
|
||||
|
@ -122,6 +122,7 @@ pub use {
|
|||
lang_item::LangItem,
|
||||
nameres::{DefMap, ModuleSource},
|
||||
path::{ModPath, PathKind},
|
||||
per_ns::Namespace,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
visibility::Visibility,
|
||||
// FIXME: This is here since some queries take it as input that are used
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
use base_db::FileRange;
|
||||
use hir_def::{
|
||||
src::HasSource, AdtId, AssocItemId, DefWithBodyId, HasModule, ImplId, Lookup, MacroId,
|
||||
ModuleDefId, ModuleId, TraitId,
|
||||
item_scope::ItemInNs,
|
||||
src::{HasChildSource, HasSource},
|
||||
AdtId, AssocItemId, DefWithBodyId, HasModule, ImplId, Lookup, MacroId, ModuleDefId, ModuleId,
|
||||
TraitId,
|
||||
};
|
||||
use hir_expand::{HirFileId, InFile};
|
||||
use hir_ty::db::HirDatabase;
|
||||
|
@ -167,6 +169,40 @@ impl<'a> SymbolCollector<'a> {
|
|||
self.collect_from_impl(impl_id);
|
||||
}
|
||||
|
||||
// Record renamed imports.
|
||||
// In case it imports multiple items under different namespaces we just pick one arbitrarily
|
||||
// for now.
|
||||
for id in scope.imports() {
|
||||
let loc = id.import.lookup(self.db.upcast());
|
||||
loc.id.item_tree(self.db.upcast());
|
||||
let source = id.import.child_source(self.db.upcast());
|
||||
let Some(use_tree_src) = source.value.get(id.idx) else { continue };
|
||||
let Some(rename) = use_tree_src.rename() else { continue };
|
||||
let Some(name) = rename.name() else { continue };
|
||||
|
||||
let res = scope.fully_resolve_import(self.db.upcast(), id);
|
||||
res.iter_items().for_each(|(item, _)| {
|
||||
let def = match item {
|
||||
ItemInNs::Types(def) | ItemInNs::Values(def) => def,
|
||||
ItemInNs::Macros(def) => ModuleDefId::from(def),
|
||||
}
|
||||
.into();
|
||||
let dec_loc = DeclarationLocation {
|
||||
hir_file_id: source.file_id,
|
||||
ptr: SyntaxNodePtr::new(use_tree_src.syntax()),
|
||||
name_ptr: SyntaxNodePtr::new(name.syntax()),
|
||||
};
|
||||
|
||||
self.symbols.push(FileSymbol {
|
||||
name: name.text().into(),
|
||||
def,
|
||||
container_name: self.current_container_name.clone(),
|
||||
loc: dec_loc,
|
||||
is_alias: false,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for const_id in scope.unnamed_consts() {
|
||||
self.collect_from_body(const_id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue