Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/hover/render.rs')
-rw-r--r--crates/ide/src/hover/render.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index 59068028ed..46fe7f2b7d 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -1,6 +1,6 @@
//! Logic for rendering the different hover messages
use either::Either;
-use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, Semantics, TypeInfo};
+use hir::{AsAssocItem, Const, HasAttrs, HasSource, HirDisplay, Semantics, TypeInfo};
use ide_db::{
base_db::SourceDatabase,
defs::Definition,
@@ -352,7 +352,7 @@ pub(super) fn definition(
Definition::Function(it) => label_and_docs(db, it),
Definition::Adt(it) => label_and_docs(db, it),
Definition::Variant(it) => label_and_docs(db, it),
- Definition::Const(it) => label_and_docs(db, it),
+ Definition::Const(it) => const_label_value_and_docs(db, it),
Definition::Static(it) => label_and_docs(db, it),
Definition::Trait(it) => label_and_docs(db, it),
Definition::TypeAlias(it) => label_and_docs(db, it),
@@ -381,6 +381,21 @@ where
(label, docs)
}
+fn const_label_value_and_docs(
+ db: &RootDatabase,
+ konst: Const,
+) -> (String, Option<hir::Documentation>) {
+ let label = if let Some(expr) = konst.value(db) {
+ format!("{} = {}", konst.display(db), expr)
+ } else {
+ konst.display(db).to_string()
+ };
+
+ let docs = konst.attrs(db).docs();
+
+ (label, docs)
+}
+
fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
if let Definition::GenericParam(_) = def {
return None;