diff --git a/crates/typst-ide/src/tooltip.rs b/crates/typst-ide/src/tooltip.rs index 9629462b8..646763535 100644 --- a/crates/typst-ide/src/tooltip.rs +++ b/crates/typst-ide/src/tooltip.rs @@ -5,7 +5,7 @@ use if_chain::if_chain; use typst::doc::Frame; use typst::eval::{CapturesVisitor, CastInfo, Repr, Tracer, Value}; use typst::geom::{round_2, Length, Numeric}; -use typst::syntax::ast::{self, AstNode}; +use typst::syntax::ast; use typst::syntax::{LinkedNode, Source, SyntaxKind}; use typst::util::{pretty_comma_list, separated_list}; use typst::World; @@ -103,16 +103,21 @@ fn expr_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option { /// Tooltip for a hovered closure. fn closure_tooltip(leaf: &LinkedNode) -> Option { - // Find the closure to analyze. - let mut ancestor = leaf; - while !ancestor.is::() { - ancestor = ancestor.parent()?; + // Only show this tooltip when hovering over the equals sign or arrow of + // the closure. Showing it across the whole subtree is too noisy. + if !matches!(leaf.kind(), SyntaxKind::Eq | SyntaxKind::Arrow) { + return None; + } + + // Find the closure to analyze. + let parent = leaf.parent()?; + if parent.kind() != SyntaxKind::Closure { + return None; } - let closure = ancestor.cast::()?.to_untyped(); // Analyze the closure's captures. let mut visitor = CapturesVisitor::new(None); - visitor.visit(closure); + visitor.visit(parent); let captures = visitor.finish(); let mut names: Vec<_> =