Skip to content

Commit

Permalink
go/types/internal/play: show types.Selection information
Browse files Browse the repository at this point in the history
Change-Id: I668b2fa0108d9f4cdea0f1075a4c97728435edf2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/532395
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan committed Oct 3, 2023
1 parent a819c61 commit e8722c0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions go/types/internal/play/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ func handleSelectJSON(w http.ResponseWriter, req *http.Request) {
}
}

// selection x.f information (if cursor is over .f)
for _, n := range path[:2] {
if sel, ok := n.(*ast.SelectorExpr); ok {
seln, ok := pkg.TypesInfo.Selections[sel]
if ok {
fmt.Fprintf(out, "Selection: %s recv=%v obj=%v type=%v indirect=%t index=%d\n\n",
strings.Fields("FieldVal MethodVal MethodExpr")[seln.Kind()],
seln.Recv(),
seln.Obj(),
seln.Type(),
seln.Indirect(),
seln.Index())

} else {
fmt.Fprintf(out, "Selector is qualified identifier.\n\n")
}
break
}
}

// Object type information.
switch n := path[0].(type) {
case *ast.Ident:
Expand Down

0 comments on commit e8722c0

Please sign in to comment.