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

Use the Go file filtering done by build.Default.Import #61

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions go/types/goodarch.go

This file was deleted.

24 changes: 10 additions & 14 deletions go/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/rogpeppe/godef/go/ast"
"github.com/rogpeppe/godef/go/parser"
Expand Down Expand Up @@ -82,7 +81,16 @@ func DefaultImporter(path string, srcDir string) *ast.Package {
if err != nil {
return nil
}
pkgs, err := parser.ParseDir(FileSet, bpkg.Dir, isGoFile, 0, DefaultImportPathToName)
// Create a map for fast lookup of the files we want to parse
parseFiles := make(map[string]struct{}, len(bpkg.GoFiles))
for _, name := range bpkg.GoFiles {
parseFiles[name] = struct{}{}
}
filter := func(d os.FileInfo) bool {
_, found := parseFiles[d.Name()]
return found
}
pkgs, err := parser.ParseDir(FileSet, bpkg.Dir, filter, 0, DefaultImportPathToName)
if err != nil {
if Debug {
switch err := err.(type) {
Expand Down Expand Up @@ -112,18 +120,6 @@ func DefaultImportPathToName(path, srcDir string) (string, error) {
return pkg.Name, err
}

// isGoFile returns true if we will consider the file as a
// possible candidate for parsing as part of a package.
// Including _test.go here isn't quite right, but what
// else can we do?
//
func isGoFile(d os.FileInfo) bool {
return strings.HasSuffix(d.Name(), ".go") &&
!strings.HasSuffix(d.Name(), "_test.go") &&
!strings.HasPrefix(d.Name(), ".") &&
goodOSArch(d.Name())
}

// When Debug is true, log messages will be printed.
var Debug = false

Expand Down