From ec21927d08d380c2b760a152c821910d57475ff2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 29 Jan 2023 00:24:54 +0100 Subject: [PATCH] Find first hovered ancestor expression --- src/ide/tooltip.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ide/tooltip.rs b/src/ide/tooltip.rs index 4a03e5b80..26fa3625c 100644 --- a/src/ide/tooltip.rs +++ b/src/ide/tooltip.rs @@ -32,12 +32,17 @@ pub enum Tooltip { /// Tooltip for a hovered expression. fn expr_tooltip(world: &(dyn World + 'static), leaf: &LinkedNode) -> Option { - let expr = leaf.cast::()?; + let mut ancestor = leaf; + while !ancestor.is::() { + ancestor = ancestor.parent()?; + } + + let expr = ancestor.cast::()?; if !expr.hashtag() { return None; } - let values = analyze(world, leaf); + let values = analyze(world, ancestor); if let [value] = values.as_slice() { if let Some(docs) = value.docs() {