Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 3 additions & 9 deletions refactor/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@ func deleteUnusedImports(s *Snapshot, p *Package, text []byte) []byte {
}
})

match := func(name, pkg string) bool {
match := func(name, importPath string) bool {
if name == "" {
var p1 *Package
if path, ok := p.ImportMap[pkg]; ok {
p1 = s.pkgGraph.byPath(path)
}
if p1 == nil {
p1 = s.pkgGraph.byPath(pkg)
}
p1 := s.pkgGraph.byPath(p.ImportMap.Lookup(importPath))
if p1 == nil {
panic("NO IMPORT: " + pkg)
panic("NO IMPORT: " + importPath)
}
name = p1.Name
}
Expand Down
29 changes: 17 additions & 12 deletions refactor/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ type Snapshot struct {
sizes types.Sizes
}

// From local import path to package path (used for vendored packages in std)
type importMap map[string]string

// Lookup returns the pkgPath for the given import path.
func (im importMap) Lookup(importPath string) string {
if pkgPath, ok := im[importPath]; ok {
return pkgPath
}
return importPath
}

type Package struct {
Name string
Dir string
Expand All @@ -69,7 +80,7 @@ type Package struct {
InCurrentModule bool
Export string
BuildID string
ImportMap map[string]string // from local import path to package path (used for vendored packages in std)
ImportMap importMap

Types *types.Package
TypesInfo *types.Info
Expand Down Expand Up @@ -833,24 +844,18 @@ type snapImporter struct {
p *Package
}

func (s *snapImporter) Import(path string) (*types.Package, error) {
if path1, ok := s.p.ImportMap[path]; ok {
// This is a vendored package in std, so we need to remap the "local"
// import path to the unique vendored import path.
path = path1
}

p := s.s.pkgGraph.byPath(path)
func (s *snapImporter) Import(importPath string) (*types.Package, error) {
p := s.s.pkgGraph.byPath(s.p.ImportMap.Lookup(importPath))
if debugTypeCheck {
fmt.Printf("import %s %p resolve %s => %s %p\n", s.p.ID, s.p, path, p.ID, p)
fmt.Printf("import %s %p resolve %s => %s %p\n", s.p.ID, s.p, importPath, p.ID, p)
}
if p == nil {
return nil, fmt.Errorf("import not available: %s", path)
return nil, fmt.Errorf("import not available: %s", importPath)
}
if p.Types == nil {
// We are running the type-checking in dependency order,
// so if this happens, it's a mistake.
return nil, fmt.Errorf("internal error - import not yet available:")
return nil, fmt.Errorf("internal error - import not yet available: %s", importPath)
}
return p.Types, nil
}
Expand Down
Loading