go/types/internal/play: show Cursor.Stack of selected node

Change-Id: Iaf6a6369e05ded0b10b85f468d8fbf91269373e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/655135
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/go/types/internal/play/play.go b/go/types/internal/play/play.go
index f1318ac..4212a6b 100644
--- a/go/types/internal/play/play.go
+++ b/go/types/internal/play/play.go
@@ -30,8 +30,10 @@
 	"strings"
 
 	"golang.org/x/tools/go/ast/astutil"
+	"golang.org/x/tools/go/ast/inspector"
 	"golang.org/x/tools/go/packages"
 	"golang.org/x/tools/go/types/typeutil"
+	"golang.org/x/tools/internal/astutil/cursor"
 	"golang.org/x/tools/internal/typeparams"
 )
 
@@ -161,6 +163,15 @@
 			innermostExpr = e
 		}
 	}
+	// Show the cursor stack too.
+	// It's usually the same, but may differ in edge
+	// cases (e.g. around FuncType.Func).
+	inspect := inspector.New([]*ast.File{file})
+	if cur, ok := cursor.Root(inspect).FindPos(startPos, endPos); ok {
+		fmt.Fprintf(out, "Cursor.FindPos().Stack() = %v\n", cur.Stack(nil))
+	} else {
+		fmt.Fprintf(out, "Cursor.FindPos() failed\n")
+	}
 	fmt.Fprintf(out, "\n")
 
 	// Expression type information