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.rs98
1 files changed, 68 insertions, 30 deletions
diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs
index ae70f6f0ec..679f775e1b 100644
--- a/crates/hir/src/symbols.rs
+++ b/crates/hir/src/symbols.rs
@@ -2,7 +2,7 @@
use either::Either;
use hir_def::{
- AdtId, AssocItemId, DefWithBodyId, ExternCrateId, HasModule, ImplId, Lookup, MacroId,
+ AdtId, AssocItemId, Complete, DefWithBodyId, ExternCrateId, HasModule, ImplId, Lookup, MacroId,
ModuleDefId, ModuleId, TraitId,
db::DefDatabase,
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob},
@@ -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)]
@@ -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(_) => {}
@@ -194,6 +203,7 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc,
is_alias: false,
is_assoc: false,
+ do_not_complete: Complete::Yes,
});
};
@@ -223,6 +233,7 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc,
is_alias: false,
is_assoc: false,
+ do_not_complete: Complete::Yes,
});
};
@@ -281,10 +292,10 @@ impl<'a> SymbolCollector<'a> {
for &id in id {
if id.module(self.db.upcast()) == 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),
+ };
}
}
}
@@ -314,16 +325,16 @@ impl<'a> SymbolCollector<'a> {
);
self.with_container_name(impl_name, |s| {
for &(ref name, assoc_item_id) in &self.db.impl_items(impl_id).items {
- s.push_assoc_item(assoc_item_id, name)
+ s.push_assoc_item(assoc_item_id, name, None)
}
})
}
- fn collect_from_trait(&mut self, trait_id: TraitId) {
+ fn collect_from_trait(&mut self, trait_id: TraitId, trait_do_not_complete: Complete) {
let trait_data = self.db.trait_data(trait_id);
self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
for &(ref name, assoc_item_id) in &self.db.trait_items(trait_id).items {
- s.push_assoc_item(assoc_item_id, name);
+ s.push_assoc_item(assoc_item_id, name, Some(trait_do_not_complete));
}
});
}
@@ -338,15 +349,26 @@ 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<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 = dyn DefDatabase> + Into<ModuleDefId>,
<L as Lookup>::Data: HasSource,
@@ -354,7 +376,7 @@ impl<'a> SymbolCollector<'a> {
{
let loc = id.lookup(self.db.upcast());
let source = loc.source(self.db.upcast());
- let Some(name_node) = source.value.name() else { return };
+ 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,7 +412,10 @@ 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) {
@@ -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,
});
}
}