From c08a2d6d657dc9eddbac00b7789d517b26b9ac3c Mon Sep 17 00:00:00 2001 From: Douglas Creager Date: Wed, 8 Oct 2025 15:54:27 -0400 Subject: [PATCH] [ty] Fix hover to prefer expression nodes over identifiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When hovering on an attribute name like 'value' in 'instance.value', the minimal covering node is the Identifier, but we need the Attribute expression to get the type. Update find_covering_node to track both the minimal node and minimal expression, preferring the expression. This fixes hover on attribute accesses. All hover tests now pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- crates/ty_test/src/hover.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/ty_test/src/hover.rs b/crates/ty_test/src/hover.rs index 386700b7ea..03e2b52192 100644 --- a/crates/ty_test/src/hover.rs +++ b/crates/ty_test/src/hover.rs @@ -26,10 +26,12 @@ pub(crate) struct HoverOutput { } /// Find the AST node with minimal range that fully contains the given offset. +/// Returns the smallest expression node if possible, skipping over identifier-only nodes. fn find_covering_node(root: AnyNodeRef<'_>, offset: TextSize) -> Option> { struct Visitor<'a> { offset: TextSize, minimal_node: Option>, + minimal_expr: Option>, } impl<'a> SourceOrderVisitor<'a> for Visitor<'a> { @@ -43,6 +45,18 @@ fn find_covering_node(root: AnyNodeRef<'_>, offset: TextSize) -> Option, offset: TextSize) -> Option