Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
x/tools/go/packages: document whether Package.GoFiles and Package.Syntax contain the files in the same order #26915
The documentation for packages.Package.GoFiles says:
// GoFiles lists the absolute file paths of the package's Go source files. GoFiles string
The documentation for packages.Package.Syntax says:
// Syntax is the package's syntax trees, for the files listed in GoFiles. // // Mode LoadSyntax set this field for packages matching the patterns. // Mode LoadSyntaxAll sets this field for all packages, including dependencies. Syntax *ast.File
Are these always going to be in the same order?
Specifically, I'm trying to alter the contents of an
The order will usually be the same, but GoFiles is not always the precise list of files seen by the compiler---look at the CompiledGoFiles field for that. You can assume a correspondence between CompiledGoFiles and Syntax, or you can obtain the filename from the syntax tree using
We should indeed document this more clearly.