diff --git a/internal/api/session.go b/internal/api/session.go index 8308bf7c6c0..6f7be469e35 100644 --- a/internal/api/session.go +++ b/internal/api/session.go @@ -1838,7 +1838,13 @@ func (s *Session) resolveNodeHandle(program *compiler.Program, handle Handle[ast } // Verify the kind and end match - if node.Kind != kind || node.End() != end { + if node.Kind != kind || node.Pos() != pos || node.End() != end { + // Try to find the exact node by walking ancestors + for parent := node.Parent; parent != nil && parent.Kind != ast.KindSourceFile; parent = parent.Parent { + if parent.Pos() == pos && parent.End() == end && parent.Kind == kind { + return parent, nil + } + } // Try to find the exact node by walking children var found *ast.Node node.ForEachChild(func(child *ast.Node) bool {