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

Open
kevinburke opened this issue Aug 10, 2018 · 2 comments
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@kevinburke
Copy link
Contributor

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
@bcmills
Copy link
Contributor

bcmills commented Aug 10, 2018

CC: @ianthehat @alandonovan

@alandonovan
Copy link
Contributor

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.

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 10, 2018
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants