Support generic function in generate_function assist

This commit is contained in:
Ryo Yoshida 2023-01-31 19:49:18 +09:00
parent 32955c30cd
commit 3edde6fcc1
No known key found for this signature in database
GPG key ID: E25698A930586171
5 changed files with 888 additions and 45 deletions

View file

@ -2165,6 +2165,16 @@ impl AsAssocItem for ModuleDef {
}
}
}
impl AsAssocItem for DefWithBody {
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
match self {
DefWithBody::Function(it) => it.as_assoc_item(db),
DefWithBody::Const(it) => it.as_assoc_item(db),
DefWithBody::Static(_) | DefWithBody::Variant(_) => None,
}
}
}
fn as_assoc_item<ID, DEF, CTOR, AST>(db: &dyn HirDatabase, ctor: CTOR, id: ID) -> Option<AssocItem>
where
ID: Lookup<Data = AssocItemLoc<AST>>,
@ -2560,6 +2570,14 @@ impl GenericParam {
GenericParam::LifetimeParam(it) => it.name(db),
}
}
pub fn parent(self) -> GenericDef {
match self {
GenericParam::TypeParam(it) => it.id.parent().into(),
GenericParam::ConstParam(it) => it.id.parent().into(),
GenericParam::LifetimeParam(it) => it.id.parent.into(),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]