aboutsummaryrefslogtreecommitdiff
path: root/internal/imports/mod.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/imports/mod.go')
-rw-r--r--internal/imports/mod.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/internal/imports/mod.go b/internal/imports/mod.go
index dff6d5536..2bcf41f5f 100644
--- a/internal/imports/mod.go
+++ b/internal/imports/mod.go
@@ -34,7 +34,8 @@ type ModuleResolver struct {
scannedRoots map[gopathwalk.Root]bool
initialized bool
- main *gocommand.ModuleJSON
+ mains []*gocommand.ModuleJSON
+ mainByDir map[string]*gocommand.ModuleJSON
modsByModPath []*gocommand.ModuleJSON // All modules, ordered by # of path components in module Path...
modsByDir []*gocommand.ModuleJSON // ...or Dir.
@@ -69,21 +70,21 @@ func (r *ModuleResolver) init() error {
Logf: r.env.Logf,
WorkingDir: r.env.WorkingDir,
}
- mainMod, vendorEnabled, err := gocommand.VendorEnabled(context.TODO(), inv, r.env.GocmdRunner)
+ vendorEnabled, mainModVendor, err := gocommand.VendorEnabled(context.TODO(), inv, r.env.GocmdRunner)
if err != nil {
return err
}
- if mainMod != nil && vendorEnabled {
+ if mainModVendor != nil && vendorEnabled {
// Vendor mode is on, so all the non-Main modules are irrelevant,
// and we need to search /vendor for everything.
- r.main = mainMod
+ r.mains = []*gocommand.ModuleJSON{mainModVendor}
r.dummyVendorMod = &gocommand.ModuleJSON{
Path: "",
- Dir: filepath.Join(mainMod.Dir, "vendor"),
+ Dir: filepath.Join(mainModVendor.Dir, "vendor"),
}
- r.modsByModPath = []*gocommand.ModuleJSON{mainMod, r.dummyVendorMod}
- r.modsByDir = []*gocommand.ModuleJSON{mainMod, r.dummyVendorMod}
+ r.modsByModPath = []*gocommand.ModuleJSON{mainModVendor, r.dummyVendorMod}
+ r.modsByDir = []*gocommand.ModuleJSON{mainModVendor, r.dummyVendorMod}
} else {
// Vendor mode is off, so run go list -m ... to find everything.
err := r.initAllMods()
@@ -122,8 +123,10 @@ func (r *ModuleResolver) init() error {
r.roots = []gopathwalk.Root{
{filepath.Join(goenv["GOROOT"], "/src"), gopathwalk.RootGOROOT},
}
- if r.main != nil {
- r.roots = append(r.roots, gopathwalk.Root{r.main.Dir, gopathwalk.RootCurrentModule})
+ r.mainByDir = make(map[string]*gocommand.ModuleJSON)
+ for _, main := range r.mains {
+ r.roots = append(r.roots, gopathwalk.Root{main.Dir, gopathwalk.RootCurrentModule})
+ r.mainByDir[main.Dir] = main
}
if vendorEnabled {
r.roots = append(r.roots, gopathwalk.Root{r.dummyVendorMod.Dir, gopathwalk.RootOther})
@@ -189,7 +192,7 @@ func (r *ModuleResolver) initAllMods() error {
r.modsByModPath = append(r.modsByModPath, mod)
r.modsByDir = append(r.modsByDir, mod)
if mod.Main {
- r.main = mod
+ r.mains = append(r.mains, mod)
}
}
return nil
@@ -609,7 +612,7 @@ func (r *ModuleResolver) scanDirForPackage(root gopathwalk.Root, dir string) dir
}
switch root.Type {
case gopathwalk.RootCurrentModule:
- importPath = path.Join(r.main.Path, filepath.ToSlash(subdir))
+ importPath = path.Join(r.mainByDir[root.Path].Path, filepath.ToSlash(subdir))
case gopathwalk.RootModuleCache:
matches := modCacheRegexp.FindStringSubmatch(subdir)
if len(matches) == 0 {