Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/symbols.rs')
-rw-r--r--crates/hir/src/symbols.rs142
1 files changed, 90 insertions, 52 deletions
diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs
index 81eb6a70ad..41064d047a 100644
--- a/crates/hir/src/symbols.rs
+++ b/crates/hir/src/symbols.rs
@@ -2,22 +2,22 @@
use either::Either;
use hir_def::{
+ AdtId, AssocItemId, Complete, DefWithBodyId, ExternCrateId, HasModule, ImplId, Lookup, MacroId,
+ ModuleDefId, ModuleId, TraitId,
db::DefDatabase,
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob},
per_ns::Item,
src::{HasChildSource, HasSource},
visibility::{Visibility, VisibilityExplicitness},
- AdtId, AssocItemId, DefWithBodyId, ExternCrateId, HasModule, ImplId, Lookup, MacroId,
- ModuleDefId, ModuleId, TraitId,
};
-use hir_expand::{name::Name, HirFileId};
+use hir_expand::{HirFileId, name::Name};
use hir_ty::{
db::HirDatabase,
- display::{hir_display_with_types_map, DisplayTarget, HirDisplay},
+ display::{DisplayTarget, HirDisplay, hir_display_with_store},
};
use intern::Symbol;
use rustc_hash::FxHashMap;
-use syntax::{ast::HasName, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr};
+use syntax::{AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};
use crate::{Module, ModuleDef, Semantics};
@@ -34,6 +34,7 @@ pub struct FileSymbol {
/// Whether this symbol is a doc alias for the original symbol.
pub is_alias: bool,
pub is_assoc: bool,
+ pub do_not_complete: Complete,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -79,7 +80,7 @@ impl<'a> SymbolCollector<'a> {
current_container_name: None,
display_target: DisplayTarget::from_crate(
db,
- *db.crate_graph().crates_in_topological_order().last().unwrap(),
+ *db.all_crates().last().expect("no crate graph present"),
),
}
}
@@ -111,7 +112,7 @@ impl<'a> SymbolCollector<'a> {
fn do_work(&mut self, work: SymbolCollectorWork) {
let _p = tracing::info_span!("SymbolCollector::do_work", ?work).entered();
tracing::info!(?work, "SymbolCollector::do_work");
- self.db.unwind_if_cancelled();
+ self.db.unwind_if_revision_cancelled();
let parent_name = work.parent.map(|name| name.as_str().to_smolstr());
self.with_container_name(parent_name, |s| s.collect_from_module(work.module_id));
@@ -122,35 +123,43 @@ impl<'a> SymbolCollector<'a> {
match def {
ModuleDefId::ModuleId(id) => this.push_module(id, name),
ModuleDefId::FunctionId(id) => {
- this.push_decl(id, name, false);
+ this.push_decl(id, name, false, None);
this.collect_from_body(id, Some(name.clone()));
}
- ModuleDefId::AdtId(AdtId::StructId(id)) => this.push_decl(id, name, false),
- ModuleDefId::AdtId(AdtId::EnumId(id)) => this.push_decl(id, name, false),
- ModuleDefId::AdtId(AdtId::UnionId(id)) => this.push_decl(id, name, false),
+ ModuleDefId::AdtId(AdtId::StructId(id)) => {
+ this.push_decl(id, name, false, None);
+ }
+ ModuleDefId::AdtId(AdtId::EnumId(id)) => {
+ this.push_decl(id, name, false, None);
+ }
+ ModuleDefId::AdtId(AdtId::UnionId(id)) => {
+ this.push_decl(id, name, false, None);
+ }
ModuleDefId::ConstId(id) => {
- this.push_decl(id, name, false);
+ this.push_decl(id, name, false, None);
this.collect_from_body(id, Some(name.clone()));
}
ModuleDefId::StaticId(id) => {
- this.push_decl(id, name, false);
+ this.push_decl(id, name, false, None);
this.collect_from_body(id, Some(name.clone()));
}
ModuleDefId::TraitId(id) => {
- this.push_decl(id, name, false);
- this.collect_from_trait(id);
+ let trait_do_not_complete = this.push_decl(id, name, false, None);
+ this.collect_from_trait(id, trait_do_not_complete);
}
ModuleDefId::TraitAliasId(id) => {
- this.push_decl(id, name, false);
+ this.push_decl(id, name, false, None);
}
ModuleDefId::TypeAliasId(id) => {
- this.push_decl(id, name, false);
+ this.push_decl(id, name, false, None);
+ }
+ ModuleDefId::MacroId(id) => {
+ match id {
+ MacroId::Macro2Id(id) => this.push_decl(id, name, false, None),
+ MacroId::MacroRulesId(id) => this.push_decl(id, name, false, None),
+ MacroId::ProcMacroId(id) => this.push_decl(id, name, false, None),
+ };
}
- ModuleDefId::MacroId(id) => match id {
- MacroId::Macro2Id(id) => this.push_decl(id, name, false),
- MacroId::MacroRulesId(id) => this.push_decl(id, name, false),
- MacroId::ProcMacroId(id) => this.push_decl(id, name, false),
- },
// Don't index these.
ModuleDefId::BuiltinType(_) => {}
ModuleDefId::EnumVariantId(_) => {}
@@ -169,7 +178,7 @@ impl<'a> SymbolCollector<'a> {
let mut push_import = |this: &mut Self, i: ImportId, name: &Name, def: ModuleDefId, vis| {
let source = import_child_source_cache
.entry(i.use_)
- .or_insert_with(|| i.use_.child_source(this.db.upcast()));
+ .or_insert_with(|| i.use_.child_source(this.db));
let Some(use_tree_src) = source.value.get(i.idx) else { return };
let rename = use_tree_src.rename().and_then(|rename| rename.name());
let name_syntax = match rename {
@@ -194,13 +203,14 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc,
is_alias: false,
is_assoc: false,
+ do_not_complete: Complete::Yes,
});
};
let push_extern_crate =
|this: &mut Self, i: ExternCrateId, name: &Name, def: ModuleDefId, vis| {
- let loc = i.lookup(this.db.upcast());
- let source = loc.source(this.db.upcast());
+ let loc = i.lookup(this.db);
+ let source = loc.source(this.db);
let rename = source.value.rename().and_then(|rename| rename.name());
let name_syntax = match rename {
@@ -223,10 +233,11 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc,
is_alias: false,
is_assoc: false,
+ do_not_complete: Complete::Yes,
});
};
- let def_map = module_id.def_map(self.db.upcast());
+ let def_map = module_id.def_map(self.db);
let scope = &def_map[module_id.local_id].scope;
for impl_id in scope.impls() {
@@ -279,12 +290,12 @@ impl<'a> SymbolCollector<'a> {
for (name, id) in scope.legacy_macros() {
for &id in id {
- if id.module(self.db.upcast()) == module_id {
+ if id.module(self.db) == module_id {
match id {
- MacroId::Macro2Id(id) => self.push_decl(id, name, false),
- MacroId::MacroRulesId(id) => self.push_decl(id, name, false),
- MacroId::ProcMacroId(id) => self.push_decl(id, name, false),
- }
+ MacroId::Macro2Id(id) => self.push_decl(id, name, false, None),
+ MacroId::MacroRulesId(id) => self.push_decl(id, name, false, None),
+ MacroId::ProcMacroId(id) => self.push_decl(id, name, false, None),
+ };
}
}
}
@@ -295,7 +306,7 @@ impl<'a> SymbolCollector<'a> {
let body = self.db.body(body_id);
// Descend into the blocks and enqueue collection of all modules within.
- for (_, def_map) in body.blocks(self.db.upcast()) {
+ for (_, def_map) in body.blocks(self.db) {
for (id, _) in def_map.modules() {
self.work.push(SymbolCollectorWork {
module_id: def_map.module_id(id),
@@ -306,24 +317,24 @@ impl<'a> SymbolCollector<'a> {
}
fn collect_from_impl(&mut self, impl_id: ImplId) {
- let impl_data = self.db.impl_data(impl_id);
+ let impl_data = self.db.impl_signature(impl_id);
let impl_name = Some(
- hir_display_with_types_map(impl_data.self_ty, &impl_data.types_map)
+ hir_display_with_store(impl_data.self_ty, &impl_data.store)
.display(self.db, self.display_target)
.to_smolstr(),
);
self.with_container_name(impl_name, |s| {
- for &(ref name, assoc_item_id) in &impl_data.items {
- s.push_assoc_item(assoc_item_id, name)
+ for &(ref name, assoc_item_id) in &self.db.impl_items(impl_id).items {
+ s.push_assoc_item(assoc_item_id, name, None)
}
})
}
- fn collect_from_trait(&mut self, trait_id: TraitId) {
- let trait_data = self.db.trait_data(trait_id);
+ fn collect_from_trait(&mut self, trait_id: TraitId, trait_do_not_complete: Complete) {
+ let trait_data = self.db.trait_signature(trait_id);
self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
- for &(ref name, assoc_item_id) in &trait_data.items {
- s.push_assoc_item(assoc_item_id, name);
+ for &(ref name, assoc_item_id) in &self.db.trait_items(trait_id).items {
+ s.push_assoc_item(assoc_item_id, name, Some(trait_do_not_complete));
}
});
}
@@ -338,23 +349,34 @@ impl<'a> SymbolCollector<'a> {
}
}
- fn push_assoc_item(&mut self, assoc_item_id: AssocItemId, name: &Name) {
+ fn push_assoc_item(
+ &mut self,
+ assoc_item_id: AssocItemId,
+ name: &Name,
+ trait_do_not_complete: Option<Complete>,
+ ) {
match assoc_item_id {
- AssocItemId::FunctionId(id) => self.push_decl(id, name, true),
- AssocItemId::ConstId(id) => self.push_decl(id, name, true),
- AssocItemId::TypeAliasId(id) => self.push_decl(id, name, true),
- }
+ AssocItemId::FunctionId(id) => self.push_decl(id, name, true, trait_do_not_complete),
+ AssocItemId::ConstId(id) => self.push_decl(id, name, true, trait_do_not_complete),
+ AssocItemId::TypeAliasId(id) => self.push_decl(id, name, true, trait_do_not_complete),
+ };
}
- fn push_decl<'db, L>(&mut self, id: L, name: &Name, is_assoc: bool)
+ fn push_decl<L>(
+ &mut self,
+ id: L,
+ name: &Name,
+ is_assoc: bool,
+ trait_do_not_complete: Option<Complete>,
+ ) -> Complete
where
- L: Lookup<Database<'db> = dyn DefDatabase + 'db> + Into<ModuleDefId>,
+ L: Lookup<Database = dyn DefDatabase> + Into<ModuleDefId>,
<L as Lookup>::Data: HasSource,
<<L as Lookup>::Data as HasSource>::Value: HasName,
{
- let loc = id.lookup(self.db.upcast());
- let source = loc.source(self.db.upcast());
- let Some(name_node) = source.value.name() else { return };
+ let loc = id.lookup(self.db);
+ let source = loc.source(self.db);
+ let Some(name_node) = source.value.name() else { return Complete::Yes };
let def = ModuleDef::from(id.into());
let dec_loc = DeclarationLocation {
hir_file_id: source.file_id,
@@ -362,7 +384,14 @@ impl<'a> SymbolCollector<'a> {
name_ptr: AstPtr::new(&name_node).wrap_left(),
};
+ let mut do_not_complete = Complete::Yes;
+
if let Some(attrs) = def.attrs(self.db) {
+ do_not_complete = Complete::extract(matches!(def, ModuleDef::Trait(_)), &attrs);
+ if let Some(trait_do_not_complete) = trait_do_not_complete {
+ do_not_complete = Complete::for_trait_item(trait_do_not_complete, do_not_complete);
+ }
+
for alias in attrs.doc_aliases() {
self.symbols.insert(FileSymbol {
name: alias.clone(),
@@ -371,6 +400,7 @@ impl<'a> SymbolCollector<'a> {
container_name: self.current_container_name.clone(),
is_alias: true,
is_assoc,
+ do_not_complete,
});
}
}
@@ -382,14 +412,17 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc,
is_alias: false,
is_assoc,
+ do_not_complete,
});
+
+ do_not_complete
}
fn push_module(&mut self, module_id: ModuleId, name: &Name) {
- let def_map = module_id.def_map(self.db.upcast());
+ let def_map = module_id.def_map(self.db);
let module_data = &def_map[module_id.local_id];
let Some(declaration) = module_data.origin.declaration() else { return };
- let module = declaration.to_node(self.db.upcast());
+ let module = declaration.to_node(self.db);
let Some(name_node) = module.name() else { return };
let dec_loc = DeclarationLocation {
hir_file_id: declaration.file_id,
@@ -399,7 +432,10 @@ impl<'a> SymbolCollector<'a> {
let def = ModuleDef::Module(module_id.into());
+ let mut do_not_complete = Complete::Yes;
if let Some(attrs) = def.attrs(self.db) {
+ do_not_complete = Complete::extract(matches!(def, ModuleDef::Trait(_)), &attrs);
+
for alias in attrs.doc_aliases() {
self.symbols.insert(FileSymbol {
name: alias.clone(),
@@ -408,6 +444,7 @@ impl<'a> SymbolCollector<'a> {
container_name: self.current_container_name.clone(),
is_alias: true,
is_assoc: false,
+ do_not_complete,
});
}
}
@@ -419,6 +456,7 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc,
is_alias: false,
is_assoc: false,
+ do_not_complete,
});
}
}