Properly support IDE functionality in enum variants

This commit is contained in:
Lukas Wirth 2022-09-23 22:48:38 +02:00
parent 14400785ac
commit 7ec9ffa325
3 changed files with 7 additions and 3 deletions

View file

@ -198,6 +198,10 @@ impl ChildBySource for EnumId {
impl ChildBySource for DefWithBodyId { impl ChildBySource for DefWithBodyId {
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
let body = db.body(*self); let body = db.body(*self);
if let &DefWithBodyId::VariantId(v) = self {
VariantId::EnumVariantId(v).child_by_source_to(db, res, file_id)
}
for (_, def_map) in body.blocks(db) { for (_, def_map) in body.blocks(db) {
// All block expressions are merged into the same map, because they logically all add // All block expressions are merged into the same map, because they logically all add
// inner items to the containing `DefWithBodyId`. // inner items to the containing `DefWithBodyId`.

View file

@ -377,10 +377,10 @@ impl ModuleDef {
ModuleDef::Function(it) => Some(it.into()), ModuleDef::Function(it) => Some(it.into()),
ModuleDef::Const(it) => Some(it.into()), ModuleDef::Const(it) => Some(it.into()),
ModuleDef::Static(it) => Some(it.into()), ModuleDef::Static(it) => Some(it.into()),
ModuleDef::Variant(it) => Some(it.into()),
ModuleDef::Module(_) ModuleDef::Module(_)
| ModuleDef::Adt(_) | ModuleDef::Adt(_)
| ModuleDef::Variant(_)
| ModuleDef::Trait(_) | ModuleDef::Trait(_)
| ModuleDef::TypeAlias(_) | ModuleDef::TypeAlias(_)
| ModuleDef::Macro(_) | ModuleDef::Macro(_)
@ -1160,7 +1160,7 @@ pub enum DefWithBody {
Const(Const), Const(Const),
Variant(Variant), Variant(Variant),
} }
impl_from!(Function, Const, Static for DefWithBody); impl_from!(Function, Const, Static, Variant for DefWithBody);
impl DefWithBody { impl DefWithBody {
pub fn module(self, db: &dyn HirDatabase) -> Module { pub fn module(self, db: &dyn HirDatabase) -> Module {

View file

@ -384,7 +384,7 @@ impl SourceToDefCtx<'_, '_> {
} else { } else {
let it = ast::Variant::cast(container.value)?; let it = ast::Variant::cast(container.value)?;
let def = self.enum_variant_to_def(InFile::new(container.file_id, it))?; let def = self.enum_variant_to_def(InFile::new(container.file_id, it))?;
VariantId::from(def).into() DefWithBodyId::from(def).into()
}; };
Some(cont) Some(cont)
} }