summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-10-29 19:36:20 +0100
committerLaurenz <laurmaedje@gmail.com>2023-10-29 19:36:20 +0100
commit265b37d12d8a800227f5731cf9310955f8486abf (patch)
treefb6d23873d9ef5ab245e649d52c0278b2f778a87
parent9c29dbf84f7d58d3dd85dfa2c336a72562ff6814 (diff)
Reduce trigger region of closure tooltip
-rw-r--r--crates/typst-ide/src/tooltip.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/crates/typst-ide/src/tooltip.rs b/crates/typst-ide/src/tooltip.rs
index 9629462b..64676353 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> {
/// Tooltip for a hovered closure.
fn closure_tooltip(leaf: &LinkedNode) -> Option<Tooltip> {
+ // 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 mut ancestor = leaf;
- while !ancestor.is::<ast::Closure>() {
- ancestor = ancestor.parent()?;
+ let parent = leaf.parent()?;
+ if parent.kind() != SyntaxKind::Closure {
+ return None;
}
- let closure = ancestor.cast::<ast::Closure>()?.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<_> =