feat(lsp): include docs on hover

This commit is contained in:
rvcas
2023-02-20 02:46:01 -05:00
committed by Lucas
parent 815d7d80c6
commit 02eaefce21
2 changed files with 29 additions and 0 deletions

View File

@@ -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 {