Skip to content

Fix loading packages with Go modules disabled #291

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion v2/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"go/ast"
"go/build"
"go/constant"
"go/token"
gotypes "go/types"
Expand Down Expand Up @@ -129,7 +130,14 @@ func (p *Parser) findPackages(baseCfg *packages.Config, patterns ...string) ([]s
}
var allErrs []error
for _, pkg := range pkgs {
results = append(results, pkg.PkgPath)
pkgPath := pkg.PkgPath
if pkgPath[0] == '_' && strings.HasPrefix(pkgPath[1:], build.Default.GOPATH) {
// If GOPATH mode is used, the PkgPath returned by packages.Load
// will be of the form "_<GOPATH>/src/<IMPORT_PATH>". We thus
// reslice the string to only get the <IMPORT_PATH> part.
pkgPath = pkg.PkgPath[len(build.Default.GOPATH)+6:]
}
results = append(results, pkgPath)

// pkg.Errors is not a slice of `error`, but concrete types. We have
// to iteratively convert each one into `error`.
Expand Down