mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-12-23 08:47:50 +00:00
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:
parent
ac97c34d0f
commit
8129c6741e
7 changed files with 54 additions and 4 deletions
|
|
@ -0,0 +1,6 @@
|
|||
// path: themod.typ
|
||||
/// = The Module (Alias)
|
||||
-----
|
||||
#import "themod.typ" as thatmod
|
||||
|
||||
#(/* position after */ thatmod)
|
||||
4
crates/tinymist-query/src/fixtures/hover/module_path.typ
Normal file
4
crates/tinymist-query/src/fixtures/hover/module_path.typ
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// path: some-module.typ
|
||||
/// = Some Module
|
||||
-----
|
||||
#import /* position after */ "some-module.typ"
|
||||
6
crates/tinymist-query/src/fixtures/hover/module_var.typ
Normal file
6
crates/tinymist-query/src/fixtures/hover/module_var.typ
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// path: themod.typ
|
||||
/// = The Module
|
||||
-----
|
||||
#import "themod.typ"
|
||||
|
||||
#(/* position after */ themod)
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue