Skip to content

Commit

Permalink
Keep track of files in a package
Browse files Browse the repository at this point in the history
  • Loading branch information
korfuri committed Jul 14, 2017
1 parent f349ed5 commit f9b1ae5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type Package struct {
// Name of the package
Name string

// Files in this package
Files []string

// OutRefs and InRefs are slices of references. For OutRefs
// the Ref is to an identifier in another package. For InRefs
// the Ref is to an identifier within this package. Most
Expand Down
3 changes: 3 additions & 0 deletions packagegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func (pg *PackageGraph) loadPackage(prog *loader.Program, loadpath string, pi *l

// Iterate over all files in that package.
for _, f := range pi.Files {
// Add that file to the package's file list
pkg.Files = append(pkg.Files, corpus.Rel(prog.Fset.File(f.Package).Name()))

// Iterate over all imports in that file
for _, imported := range f.Imports {
// Find the import's load-path and load that
Expand Down
1 change: 1 addition & 0 deletions simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestSimplePackage(t *testing.T) {
assert.Contains(t, pg.Packages, "fmt")
pkg := pg.Packages[pkgpath]
assert.Empty(t, pkg.InRefs)
assert.Contains(t, pkg.Files, filepath)

testutils.AssertPresenceOfRef(t, pg.Packages["fmt"], "fmt", pkg, "fmt", goref.Import, true)

Expand Down

0 comments on commit f9b1ae5

Please sign in to comment.