feat: provide docs when hovering on module refs (#751)

* feat: hover for module-level docs

* test: update snapshot

* test: update snapshot
This commit is contained in:
Myriad-Dreamin 2024-10-30 17:07:47 +08:00 committed by GitHub
parent ac97c34d0f
commit 8129c6741e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 4 deletions

View file

@ -0,0 +1,6 @@
// path: themod.typ
/// = The Module (Alias)
-----
#import "themod.typ" as thatmod
#(/* position after */ thatmod)

View file

@ -0,0 +1,4 @@
// path: some-module.typ
/// = Some Module
-----
#import /* position after */ "some-module.typ"

View file

@ -0,0 +1,6 @@
// path: themod.typ
/// = The Module
-----
#import "themod.typ"
#(/* position after */ themod)

View file

@ -0,0 +1,9 @@
---
source: crates/tinymist-query/src/hover.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/hover/module_alias.typ
---
{
"contents": "# The Module (Alias)",
"range": "2:24:2:31"
}

View file

@ -0,0 +1,9 @@
---
source: crates/tinymist-query/src/hover.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/hover/module_path.typ
---
{
"contents": "# Some Module",
"range": "0:29:0:46"
}

View file

@ -0,0 +1,9 @@
---
source: crates/tinymist-query/src/hover.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/hover/module_var.typ
---
{
"contents": "# The Module",
"range": "2:24:2:30"
}

View file

@ -275,7 +275,15 @@ fn def_tooltip(
render_actions(&mut results, actions);
Some(LspHoverContents::Array(results))
}
PathStem(..) | Var(..) => {
ModuleAlias(..) | Module(..) | PathStem(..) | ImportPath(..) | IncludePath(..) => {
let id = def.decl.file_id()?;
let src = ctx.source_by_id(id).ok()?;
let ei = ctx.expr_stage(&src);
let docs = ei.module_docstring.docs.clone()?;
results.push(MarkedString::String(docs.as_str().into()));
Some(LspHoverContents::Array(results))
}
IdentRef(..) | ImportAlias(..) | Import(..) | Var(..) => {
let deref_node = deref_target.node();
let sig = ctx.variable_docs(deref_target.node());
@ -319,9 +327,8 @@ fn def_tooltip(
render_actions(&mut results, actions);
Some(LspHoverContents::Array(results))
}
Pattern(..) | Docs(..) | Generated(..) | ImportAlias(..) | Constant(..) | IdentRef(..)
| ModuleAlias(..) | Module(..) | Import(..) | ContentRef(..) | StrName(..)
| ModuleImport(..) | Content(..) | ImportPath(..) | IncludePath(..) | Spread(..) => None,
Pattern(..) | Docs(..) | Generated(..) | Constant(..) | ContentRef(..) | StrName(..)
| ModuleImport(..) | Content(..) | Spread(..) => None,
}
}