Skip to content

Commit

Permalink
go/types/internal/play: show Cursor.Stack of selected node
Browse files Browse the repository at this point in the history
Change-Id: Iaf6a6369e05ded0b10b85f468d8fbf91269373e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/655135
Reviewed-by: Jonathan Amsterdam <[email protected]>
Auto-Submit: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
adonovan authored and gopherbot committed Mar 5, 2025
1 parent ece9e9b commit db6008c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions go/types/internal/play/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import (
"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"
)

Expand Down Expand Up @@ -161,6 +163,15 @@ func handleSelectJSON(w http.ResponseWriter, req *http.Request) {
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
Expand Down

0 comments on commit db6008c

Please sign in to comment.