Merge pull request #20 from markbates/pkger-hangs

pkger hangs fixes #19
This commit is contained in:
Mark Bates 2019-11-08 11:21:09 -08:00 committed by GitHub
commit 5e527e6ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -35,7 +35,7 @@ func Dir(p string) (Info, error) {
if err != nil { if err != nil {
es := err.Error() es := err.Error()
if !(strings.Contains(es, "cannot find module for path .") || strings.Contains(es, "no Go files")) { if !(strings.Contains(es, "cannot find module for path .") || strings.Contains(es, "no Go files") || strings.Contains(es, "can't load package")) {
return i, err return i, err
} }

View File

@ -80,23 +80,22 @@ func ParseDir(abs string, mode parser.Mode) ([]*ParsedSource, error) {
if !info.IsDir() { if !info.IsDir() {
return nil, fmt.Errorf("%s is not a directory", abs) return nil, fmt.Errorf("%s is not a directory", abs)
} }
dir := filepath.Dir(abs)
her, err := here.Dir(dir) her, err := here.Dir(abs)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("%w: here.Dir failed %s", err, abs)
} }
pt, err := her.Parse(strings.TrimPrefix(abs, dir)) pt, err := her.Parse(strings.TrimPrefix(abs, filepath.Dir(abs)))
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("%w: here.Parse failed %s", err, abs)
} }
fset := token.NewFileSet() fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, abs, nil, 0) pkgs, err := parser.ParseDir(fset, abs, nil, 0)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("%w: ParseDir failed %s", err, abs)
} }
var srcs []*ParsedSource var srcs []*ParsedSource