Impl HirDisplay for function hover message

This commit is contained in:
oxalica 2021-03-14 20:03:39 +08:00
parent 2bb8956a10
commit ef416e0154
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
5 changed files with 462 additions and 15 deletions

View file

@ -354,7 +354,7 @@ fn hover_for_definition(
},
mod_path,
),
ModuleDef::Function(it) => from_def_source(db, it, mod_path),
ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path),
ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
@ -383,6 +383,14 @@ fn hover_for_definition(
},
};
fn from_hir_fmt<D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
where
D: HasAttrs + HirDisplay,
{
let label = def.display(db).to_string();
from_def_source_labeled(db, def, Some(label), mod_path)
}
fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
where
D: HasSource<Ast = A> + HasAttrs + Copy,