Skip to content

Commit

Permalink
Fix error to find go.mod if targetDir is '.'
Browse files Browse the repository at this point in the history
  • Loading branch information
kanji-yomoda committed Aug 11, 2020
1 parent 22bd3a5 commit 1585533
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/astutil/astutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ func ParseAstPkg(fset *token.FileSet, pkg *ast.Package) (AstPkgWalker, error) {
for _, file := range pkg.Files {
aFilePath = fset.File(file.Package).Name()
}
pkgPath, err := packageNameOfDir(filepath.Dir(aFilePath))

dir := filepath.Dir(aFilePath)
if dir == "." {
var err error
dir, err = os.Getwd()
if err != nil {
return AstPkgWalker{}, xerrors.Errorf("get current directory: %w", err)
}
}
pkgPath, err := packageNameOfDir(dir)
if err != nil {
return AstPkgWalker{}, err
}
Expand Down Expand Up @@ -184,4 +193,4 @@ func parsePackageImport(srcDir string) (string, error) {
}
}
return "", xerrors.New("Source directory is outside GOPATH")
}
}

0 comments on commit 1585533

Please sign in to comment.