-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalProposal-AcceptedToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.
Milestone
Description
Update: see #77195 (comment) for latest.
Background: the inspector.Cursor.ParentEdge method returns both the kind and index of the edge to the cursor relative to its parent (e.g "c is the third argument to a function call"), since it is more efficient to compute both at once. However, it is common to need only the kind, resulting in statements like this one that discards the second component:
if ek, _ := cur.ParentEdge(); ek == edge.CallExpr_Args { ... }Since these often appear as one clause in a long conjunction a && ... && z, we have an internal helper function IsChildOf:
if astutil.IsChildOf(cur, edge.SelectorExpr_Sel) { ... }It is frequently used: there are currently 23 calls in x/tools.
Proposal: For convenience, we propose to publish it as a method of Cursor:
package inspector // golang.org/x/tools/go/ast/inspector
type Cursor ...
// IsChildOf(k) reports whether the first component of ParentEdge equals k.
func (Cursor) IsChildOf(edge.Kind) boolReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalProposal-AcceptedToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.
Type
Projects
Status
Accepted