feat: Show notable trait impls on hover

This commit is contained in:
Lukas Wirth 2024-01-16 16:15:56 +01:00
parent 384488c157
commit 82e8355492
7 changed files with 556 additions and 374 deletions

View file

@ -2844,6 +2844,7 @@ impl AssocItem {
AssocItem::TypeAlias(it) => Some(it.name(db)),
}
}
pub fn module(self, db: &dyn HirDatabase) -> Module {
match self {
AssocItem::Function(f) => f.module(db),
@ -2851,6 +2852,7 @@ impl AssocItem {
AssocItem::TypeAlias(t) => t.module(db),
}
}
pub fn container(self, db: &dyn HirDatabase) -> AssocItemContainer {
let container = match self {
AssocItem::Function(it) => it.id.lookup(db.upcast()).container,
@ -2886,6 +2888,27 @@ impl AssocItem {
AssocItemContainer::Impl(i) => i.trait_(db),
}
}
pub fn as_function(self) -> Option<Function> {
match self {
Self::Function(v) => Some(v),
_ => None,
}
}
pub fn as_const(self) -> Option<Const> {
match self {
Self::Const(v) => Some(v),
_ => None,
}
}
pub fn as_type_alias(self) -> Option<TypeAlias> {
match self {
Self::TypeAlias(v) => Some(v),
_ => None,
}
}
}
impl HasVisibility for AssocItem {
@ -3024,6 +3047,7 @@ impl LocalSource {
impl Local {
pub fn is_param(self, db: &dyn HirDatabase) -> bool {
// FIXME: This parses!
let src = self.primary_source(db);
match src.source.value {
Either::Left(pat) => pat