Merge #8055
8055: Implement HirDisplay for some more types r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
00c80b208b
@ -12,8 +12,8 @@
|
||||
use syntax::ast::{self, NameOwner};
|
||||
|
||||
use crate::{
|
||||
Const, ConstParam, Enum, Field, Function, HasVisibility, Module, Static, Struct, Substs, Trait,
|
||||
Type, TypeAlias, TypeParam, Union, Variant,
|
||||
Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam,
|
||||
Module, Static, Struct, Substs, Trait, Type, TypeAlias, TypeParam, Union, Variant,
|
||||
};
|
||||
|
||||
impl HirDisplay for Function {
|
||||
@ -120,6 +120,16 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for Adt {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
match self {
|
||||
Adt::Struct(it) => it.hir_fmt(f),
|
||||
Adt::Union(it) => it.hir_fmt(f),
|
||||
Adt::Enum(it) => it.hir_fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for Struct {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
|
||||
@ -211,6 +221,16 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for GenericParam {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
match self {
|
||||
GenericParam::TypeParam(it) => it.hir_fmt(f),
|
||||
GenericParam::LifetimeParam(it) => it.hir_fmt(f),
|
||||
GenericParam::ConstParam(it) => it.hir_fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for TypeParam {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
write!(f, "{}", self.name(f.db))?;
|
||||
@ -224,6 +244,12 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for LifetimeParam {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
write!(f, "{}", self.name(f.db))
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for ConstParam {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
write!(f, "const {}: ", self.name(f.db))?;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use either::Either;
|
||||
use hir::{
|
||||
Adt, AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module,
|
||||
AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module,
|
||||
ModuleDef, Semantics,
|
||||
};
|
||||
use ide_db::{
|
||||
@ -339,9 +339,7 @@ fn hover_for_definition(
|
||||
Definition::ModuleDef(it) => match it {
|
||||
ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Adt(Adt::Struct(it)) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Adt(Adt::Union(it)) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Adt(Adt::Enum(it)) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Adt(it) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Variant(it) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Const(it) => from_hir_fmt(db, it, mod_path),
|
||||
ModuleDef::Static(it) => from_hir_fmt(db, it, mod_path),
|
||||
@ -353,18 +351,10 @@ fn hover_for_definition(
|
||||
},
|
||||
Definition::Local(it) => hover_for_local(it, db),
|
||||
Definition::SelfType(impl_def) => {
|
||||
impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
|
||||
Adt::Struct(it) => from_hir_fmt(db, it, mod_path),
|
||||
Adt::Union(it) => from_hir_fmt(db, it, mod_path),
|
||||
Adt::Enum(it) => from_hir_fmt(db, it, mod_path),
|
||||
})
|
||||
impl_def.target_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path))
|
||||
}
|
||||
Definition::GenericParam(it) => from_hir_fmt(db, it, None),
|
||||
Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
|
||||
Definition::GenericParam(it) => match it {
|
||||
GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
|
||||
GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
|
||||
GenericParam::ConstParam(it) => Some(Markup::fenced_block(&it.display(db))),
|
||||
},
|
||||
};
|
||||
|
||||
fn from_hir_fmt<D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
|
||||
|
Loading…
Reference in New Issue
Block a user