Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/go/packages: document whether Package.GoFiles and Package.Syntax contain the files in the same order #26915

kevinburke opened this issue Aug 10, 2018 · 2 comments


Copy link

@kevinburke kevinburke commented Aug 10, 2018

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 *ast.File and write it back to disk. How can I get the filename of the abstract syntax tree I am trying to use?

@gopherbot gopherbot added this to the Unreleased milestone Aug 10, 2018
Copy link

@bcmills bcmills commented Aug 10, 2018

Copy link

@alandonovan alandonovan commented Aug 10, 2018

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 fset.Position(Syntax[i].Pos()).File.

We should indeed document this more clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants