Merge pull request #80 from breml/abs-path-modules

Import package by files if outside of GOPATH
This commit is contained in:
Mat Ryer 2019-01-21 17:22:14 +00:00 committed by GitHub
commit 055cc3eebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import (
"go/token" "go/token"
"go/types" "go/types"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -234,7 +235,19 @@ func pkgInfoFromPath(src string) (*loader.PackageInfo, error) {
ParserMode: parser.SpuriousErrors, ParserMode: parser.SpuriousErrors,
Cwd: src, Cwd: src,
} }
if strings.HasPrefix(pkgFull, string(filepath.Separator)) {
files, err := ioutil.ReadDir(pkgFull)
if err != nil {
return nil, err
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".go") && !strings.HasSuffix(file.Name(), "_test.go") {
conf.CreateFromFilenames(abs, file.Name())
}
}
} else {
conf.Import(pkgFull) conf.Import(pkgFull)
}
lprog, err := conf.Load() lprog, err := conf.Load()
if err != nil { if err != nil {
return nil, err return nil, err