summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-07-09 15:50:54 +0200
committerGitHub <noreply@github.com>2025-07-09 13:50:54 +0000
commitac77fdbb6ee9c4a33813a75e056cb5953d14b1db (patch)
treecc9a15b6a8f9af1f430caae7001ffc6bfce2109f
parent3aa7e861e7ffe03193d94c2cfd249739ef746f09 (diff)
Fix tooltip for figure reference (#6580)
-rw-r--r--crates/typst-ide/src/analyze.rs11
-rw-r--r--crates/typst-ide/src/tooltip.rs5
2 files changed, 13 insertions, 3 deletions
diff --git a/crates/typst-ide/src/analyze.rs b/crates/typst-ide/src/analyze.rs
index c493da81..76739fec 100644
--- a/crates/typst-ide/src/analyze.rs
+++ b/crates/typst-ide/src/analyze.rs
@@ -2,7 +2,7 @@ use comemo::Track;
use ecow::{eco_vec, EcoString, EcoVec};
use typst::foundations::{Label, Styles, Value};
use typst::layout::PagedDocument;
-use typst::model::BibliographyElem;
+use typst::model::{BibliographyElem, FigureElem};
use typst::syntax::{ast, LinkedNode, SyntaxKind};
use crate::IdeWorld;
@@ -75,8 +75,13 @@ pub fn analyze_labels(
for elem in document.introspector.all() {
let Some(label) = elem.label() else { continue };
let details = elem
- .get_by_name("caption")
- .or_else(|_| elem.get_by_name("body"))
+ .to_packed::<FigureElem>()
+ .and_then(|figure| match figure.caption.as_option() {
+ Some(Some(caption)) => Some(caption.pack_ref()),
+ _ => None,
+ })
+ .unwrap_or(elem)
+ .get_by_name("body")
.ok()
.and_then(|field| match field {
Value::Content(content) => Some(content),
diff --git a/crates/typst-ide/src/tooltip.rs b/crates/typst-ide/src/tooltip.rs
index 528f679c..e0d66a89 100644
--- a/crates/typst-ide/src/tooltip.rs
+++ b/crates/typst-ide/src/tooltip.rs
@@ -378,4 +378,9 @@ mod tests {
.with_source("other.typ", "#let f = (x) => 1");
test(&world, -4, Side::After).must_be_code("(..) => ..");
}
+
+ #[test]
+ fn test_tooltip_reference() {
+ test("#figure(caption: [Hi])[]<f> @f", -1, Side::Before).must_be_text("Hi");
+ }
}