Skip to content

Commit db6008c

Browse files
adonovangopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent ece9e9b commit db6008c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

go/types/internal/play/play.go

+11
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import (
3030
"strings"
3131

3232
"golang.org/x/tools/go/ast/astutil"
33+
"golang.org/x/tools/go/ast/inspector"
3334
"golang.org/x/tools/go/packages"
3435
"golang.org/x/tools/go/types/typeutil"
36+
"golang.org/x/tools/internal/astutil/cursor"
3537
"golang.org/x/tools/internal/typeparams"
3638
)
3739

@@ -161,6 +163,15 @@ func handleSelectJSON(w http.ResponseWriter, req *http.Request) {
161163
innermostExpr = e
162164
}
163165
}
166+
// Show the cursor stack too.
167+
// It's usually the same, but may differ in edge
168+
// cases (e.g. around FuncType.Func).
169+
inspect := inspector.New([]*ast.File{file})
170+
if cur, ok := cursor.Root(inspect).FindPos(startPos, endPos); ok {
171+
fmt.Fprintf(out, "Cursor.FindPos().Stack() = %v\n", cur.Stack(nil))
172+
} else {
173+
fmt.Fprintf(out, "Cursor.FindPos() failed\n")
174+
}
164175
fmt.Fprintf(out, "\n")
165176

166177
// Expression type information

0 commit comments

Comments
 (0)