diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs
index a8a66731..bcfb7545 100644
--- a/crates/aiken-lang/src/ast.rs
+++ b/crates/aiken-lang/src/ast.rs
@@ -324,6 +324,18 @@ impl Definition {
}
}
}
+
+ pub fn doc(&self) -> Option {
+ match self {
+ Definition::Use { .. } => None,
+ Definition::Fn(Function { doc, .. })
+ | Definition::TypeAlias(TypeAlias { doc, .. })
+ | Definition::DataType(DataType { doc, .. })
+ | Definition::ModuleConstant(ModuleConstant { doc, .. })
+ | Definition::Validator(Validator { doc, .. })
+ | Definition::Test(Function { doc, .. }) => doc.clone(),
+ }
+ }
}
impl TypedDefinition {
diff --git a/crates/aiken-lsp/src/server.rs b/crates/aiken-lsp/src/server.rs
index ac5dff9f..e06b93e9 100644
--- a/crates/aiken-lsp/src/server.rs
+++ b/crates/aiken-lsp/src/server.rs
@@ -354,6 +354,22 @@ impl Server {
Located::Definition(_) => return Ok(None),
};
+ let doc = expression
+ .definition_location()
+ .and_then(|loc| loc.module.map(|m| (m, loc.span)))
+ .and_then(|(m, span)| {
+ self.compiler
+ .as_ref()
+ .and_then(|compiler| compiler.modules.get(m))
+ .map(|checked_module| (checked_module, span))
+ })
+ .and_then(|(checked_module, span)| checked_module.ast.find_node(span.start))
+ .and_then(|node| match node {
+ Located::Expression(_) => None,
+ Located::Definition(def) => def.doc(),
+ })
+ .unwrap_or_default();
+
// Show the type of the hovered node to the user
let type_ = Printer::new().pretty_print(expression.tipo().as_ref(), 0);
@@ -361,6 +377,7 @@ impl Server {
```aiken
{type_}
```
+ {doc}
"#};
Ok(Some(lsp_types::Hover {