[tools] go/types/internal/play: show astutil.Select results too

0 views
Skip to first unread message

Alan Donovan (Gerrit)

unread,
Dec 16, 2025, 9:28:20 PM (5 hours ago) Dec 16
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Alan Donovan has uploaded the change for review

Commit message

go/types/internal/play: show astutil.Select results too
Change-Id: Ie9b6ba33f5e8e6aeaa43147d2004782953afc664

Change diff

diff --git a/go/types/internal/play/play.go b/go/types/internal/play/play.go
index 89ed975..4e17901 100644
--- a/go/types/internal/play/play.go
+++ b/go/types/internal/play/play.go
@@ -30,10 +30,11 @@
"strconv"
"strings"

- "golang.org/x/tools/go/ast/astutil"
+ goastutil "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"
"golang.org/x/tools/internal/typeparams"
)

@@ -121,7 +122,7 @@
endPos := tokFile.Pos(endOffset)

// Syntax information
- path, exact := astutil.PathEnclosingInterval(file, startPos, endPos)
+ path, exact := goastutil.PathEnclosingInterval(file, startPos, endPos)
fmt.Fprintf(out, "Path enclosing interval #%d-%d [exact=%t]:\n",
startOffset, endOffset, exact)
var innermostExpr ast.Expr
@@ -163,16 +164,26 @@
innermostExpr = e
}
}
- // Show the cursor stack too.
+ // Show the Cursor.Enclosing 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 := inspect.Root().FindByPos(startPos, endPos); ok {
- fmt.Fprintf(out, "Cursor.FindPos().Enclosing() = %v\n",
+ curFile, _ := inspector.New([]*ast.File{file}).Root().FirstChild()
+ if cur, ok := curFile.FindByPos(startPos, endPos); ok {
+ fmt.Fprintf(out, "Cursor.FindByPos().Enclosing() = %v\n",
slices.Collect(cur.Enclosing()))
} else {
fmt.Fprintf(out, "Cursor.FindPos() failed\n")
}
+ // And show the astutil.Select result (enclosing, leftmost & rightmost enclosed).
+ if curEnclosing, curStart, curEnd, err := astutil.Select(curFile, startPos, endPos); err == nil {
+ format := func(cur inspector.Cursor) string {
+ return fmt.Sprintf("%T@%v", cur.Node(), fset.Position(cur.Node().Pos()))
+ }
+ fmt.Fprintf(out, "astutil.Select() = (%s, %s, %s)\n",
+ format(curEnclosing), format(curStart), format(curEnd))
+ } else {
+ fmt.Fprintf(out, "astutil.Select() = %v", err)
+ }
fmt.Fprintf(out, "\n")

// Expression type information
@@ -266,7 +277,7 @@

// Show inventory of all objects, including addresses to disambiguate.
fmt.Fprintf(out, "Objects:\n")
- for curId := range inspect.Root().Preorder((*ast.Ident)(nil)) {
+ for curId := range curFile.Preorder((*ast.Ident)(nil)) {
id := curId.Node().(*ast.Ident)
if obj := pkg.TypesInfo.Defs[id]; obj != nil {
fmt.Fprintf(out, "%s: def %v (%p)\n", fset.Position(id.Pos()), obj, obj)

Change information

Files:
  • M go/types/internal/play/play.go
Change size: S
Delta: 1 file changed, 18 insertions(+), 7 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ie9b6ba33f5e8e6aeaa43147d2004782953afc664
Gerrit-Change-Number: 730640
Gerrit-PatchSet: 1
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Dec 16, 2025, 9:28:48 PM (5 hours ago) Dec 16
to goph...@pubsubhelper.golang.org, Hongxiang Jiang, Go LUCI, golang-co...@googlegroups.com
Attention needed from Hongxiang Jiang

Alan Donovan voted and added 1 comment

Votes added by Alan Donovan

Auto-Submit+1

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Alan Donovan . resolved

(This tool is useful for debugging AST/types/cursor issues.)

Open in Gerrit

Related details

Attention is currently required from:
  • Hongxiang Jiang
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ie9b6ba33f5e8e6aeaa43147d2004782953afc664
Gerrit-Change-Number: 730640
Gerrit-PatchSet: 1
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Attention: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Comment-Date: Wed, 17 Dec 2025 02:28:45 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Dec 16, 2025, 9:46:04 PM (5 hours ago) Dec 16
to Alan Donovan, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Hongxiang Jiang voted and added 1 comment

Votes added by Hongxiang Jiang

Code-Review+2

1 comment

Patchset-level comments
Alan Donovan . resolved

(This tool is useful for debugging AST/types/cursor issues.)

Hongxiang Jiang

I use this almost every week.

Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ie9b6ba33f5e8e6aeaa43147d2004782953afc664
Gerrit-Change-Number: 730640
Gerrit-PatchSet: 1
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Wed, 17 Dec 2025 02:45:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Alan Donovan <adon...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Dec 16, 2025, 9:48:44 PM (4 hours ago) Dec 16
to Alan Donovan, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Hongxiang Jiang, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
go/types/internal/play: show astutil.Select results too
Change-Id: Ie9b6ba33f5e8e6aeaa43147d2004782953afc664
Auto-Submit: Alan Donovan <adon...@google.com>
Reviewed-by: Hongxiang Jiang <hxj...@golang.org>
Files:
  • M go/types/internal/play/play.go
Change size: S
Delta: 1 file changed, 18 insertions(+), 7 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Hongxiang Jiang
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ie9b6ba33f5e8e6aeaa43147d2004782953afc664
Gerrit-Change-Number: 730640
Gerrit-PatchSet: 2
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages