Closed as not planned
Description
Proposal Details
I sometimes find myself writing static analysis tools which load packages and iterate something other than the syntax (like pkg.TypesInfo.Defs
) to do some analysis. Sometimes in the course of such analysis, it's useful to map some position (perhaps from a types.Object
) to its path in the AST.
The best way I've found to do this is to first find the containing *ast.File
by iterating the fileset and checking the position in question against the file's Pos()
and End()
, then subsequently calling astutil.PathEnclosingInterval
to find the path within the file.
I propose the addition of a function that combines these two operations to make this more ergonomic:
// PathContainingPos returns the node that encloses the source
// position and all its ancestors up to the AST root.
func PathContainingPos(fset *token.FileSet, pos token.Position) []ast.Node