2019-05-10 14:35:43 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-03-04 15:01:39 -07:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2019-07-09 15:52:23 -06:00
|
|
|
"bytes"
|
2019-03-05 15:30:44 -07:00
|
|
|
"context"
|
2019-10-01 13:21:06 -06:00
|
|
|
"fmt"
|
2019-03-04 15:01:39 -07:00
|
|
|
"go/ast"
|
2019-10-29 16:13:19 -06:00
|
|
|
"go/token"
|
2019-03-04 15:01:39 -07:00
|
|
|
"go/types"
|
2019-10-01 13:21:06 -06:00
|
|
|
"sort"
|
2019-06-21 15:00:02 -06:00
|
|
|
"sync"
|
2019-03-04 15:01:39 -07:00
|
|
|
|
|
|
|
"golang.org/x/tools/go/packages"
|
2019-06-21 15:00:02 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
2019-07-14 21:08:10 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/telemetry"
|
2019-07-09 15:52:23 -06:00
|
|
|
"golang.org/x/tools/internal/memoize"
|
2019-11-21 12:54:31 -07:00
|
|
|
"golang.org/x/tools/internal/span"
|
2019-10-16 17:09:37 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/log"
|
2019-08-13 13:07:39 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/trace"
|
2019-08-06 13:13:11 -06:00
|
|
|
errors "golang.org/x/xerrors"
|
2019-03-04 15:01:39 -07:00
|
|
|
)
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
// packageHandle implements source.CheckPackageHandle.
|
|
|
|
type packageHandle struct {
|
2019-07-09 15:52:23 -06:00
|
|
|
handle *memoize.Handle
|
|
|
|
|
2019-11-21 12:54:31 -07:00
|
|
|
goFiles []source.ParseGoHandle
|
|
|
|
|
2019-11-20 14:15:00 -07:00
|
|
|
// compiledGoFiles are the ParseGoHandles that compose the package.
|
|
|
|
compiledGoFiles []source.ParseGoHandle
|
2019-10-01 13:21:06 -06:00
|
|
|
|
|
|
|
// mode is the mode the the files were parsed in.
|
|
|
|
mode source.ParseMode
|
2019-07-09 15:52:23 -06:00
|
|
|
|
2019-10-01 13:21:06 -06:00
|
|
|
// m is the metadata associated with the package.
|
|
|
|
m *metadata
|
|
|
|
|
|
|
|
// key is the hashed key for the package.
|
|
|
|
key []byte
|
2019-07-09 15:52:23 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) packageKey() packageKey {
|
2019-10-01 13:21:06 -06:00
|
|
|
return packageKey{
|
2019-11-29 23:17:57 -07:00
|
|
|
id: ph.m.id,
|
|
|
|
mode: ph.mode,
|
2019-09-19 14:53:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
// packageData contains the data produced by type-checking a package.
|
|
|
|
type packageData struct {
|
2019-07-09 15:52:23 -06:00
|
|
|
memoize.NoCopy
|
|
|
|
|
|
|
|
pkg *pkg
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
// packageHandle returns a source.CheckPackageHandle for a given package and config.
|
|
|
|
func (s *snapshot) packageHandle(ctx context.Context, id packageID, mode source.ParseMode) (*packageHandle, error) {
|
2019-10-01 13:21:06 -06:00
|
|
|
// Check if we already have this CheckPackageHandle cached.
|
2019-11-29 23:17:57 -07:00
|
|
|
if ph := s.getPackage(id, mode); ph != nil {
|
|
|
|
return ph, nil
|
2019-10-01 13:21:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the CheckPackageHandle for this ID and its dependencies.
|
2019-11-29 23:17:57 -07:00
|
|
|
ph, deps, err := s.buildKey(ctx, id, mode)
|
2019-10-01 13:21:06 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-29 10:16:15 -06:00
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
// Do not close over the packageHandle or the snapshot in the Bind function.
|
2019-10-29 10:16:15 -06:00
|
|
|
// This creates a cycle, which causes the finalizers to never run on the handles.
|
|
|
|
// The possible cycles are:
|
|
|
|
//
|
2019-11-29 23:17:57 -07:00
|
|
|
// packageHandle.h.function -> packageHandle
|
|
|
|
// packageHandle.h.function -> snapshot -> packageHandle
|
2019-10-29 10:16:15 -06:00
|
|
|
//
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
m := ph.m
|
|
|
|
goFiles := ph.goFiles
|
|
|
|
compiledGoFiles := ph.compiledGoFiles
|
|
|
|
key := ph.key
|
2019-10-29 10:16:15 -06:00
|
|
|
fset := s.view.session.cache.fset
|
|
|
|
|
|
|
|
h := s.view.session.cache.store.Bind(string(key), func(ctx context.Context) interface{} {
|
2019-10-20 22:00:20 -06:00
|
|
|
// Begin loading the direct dependencies, in parallel.
|
2019-10-29 10:16:15 -06:00
|
|
|
for _, dep := range deps {
|
2019-11-29 23:17:57 -07:00
|
|
|
go func(dep *packageHandle) {
|
2019-10-20 22:00:20 -06:00
|
|
|
dep.check(ctx)
|
|
|
|
}(dep)
|
|
|
|
}
|
2019-11-29 23:17:57 -07:00
|
|
|
data := &packageData{}
|
2019-11-21 12:54:31 -07:00
|
|
|
data.pkg, data.err = typeCheck(ctx, fset, m, mode, goFiles, compiledGoFiles, deps)
|
2019-10-01 13:21:06 -06:00
|
|
|
return data
|
|
|
|
})
|
2019-11-29 23:17:57 -07:00
|
|
|
ph.handle = h
|
2019-10-01 13:21:06 -06:00
|
|
|
|
2019-10-18 13:14:59 -06:00
|
|
|
// Cache the CheckPackageHandle in the snapshot.
|
2019-11-29 23:17:57 -07:00
|
|
|
s.addPackage(ph)
|
2019-10-18 13:14:59 -06:00
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
return ph, nil
|
2019-10-01 13:21:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// buildKey computes the checkPackageKey for a given checkPackageHandle.
|
2019-11-29 23:17:57 -07:00
|
|
|
func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.ParseMode) (*packageHandle, map[packagePath]*packageHandle, error) {
|
2019-10-20 22:00:20 -06:00
|
|
|
m := s.getMetadata(id)
|
2019-09-27 11:17:59 -06:00
|
|
|
if m == nil {
|
2019-10-29 10:16:15 -06:00
|
|
|
return nil, nil, errors.Errorf("no metadata for %s", id)
|
2019-09-27 11:17:59 -06:00
|
|
|
}
|
2019-11-21 12:54:31 -07:00
|
|
|
goFiles, err := s.parseGoHandles(ctx, m.goFiles, mode)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
compiledGoFiles, err := s.parseGoHandles(ctx, m.compiledGoFiles, mode)
|
2019-05-24 14:03:39 -06:00
|
|
|
if err != nil {
|
2019-10-29 10:16:15 -06:00
|
|
|
return nil, nil, err
|
2019-05-24 14:03:39 -06:00
|
|
|
}
|
2019-11-29 23:17:57 -07:00
|
|
|
ph := &packageHandle{
|
2019-11-20 14:15:00 -07:00
|
|
|
m: m,
|
2019-11-21 12:54:31 -07:00
|
|
|
goFiles: goFiles,
|
|
|
|
compiledGoFiles: compiledGoFiles,
|
2019-11-20 14:15:00 -07:00
|
|
|
mode: mode,
|
2019-07-09 15:52:23 -06:00
|
|
|
}
|
2019-10-01 13:21:06 -06:00
|
|
|
|
2019-10-29 10:16:15 -06:00
|
|
|
// Make sure all of the depList are sorted.
|
2019-10-31 16:06:25 -06:00
|
|
|
depList := append([]packageID{}, m.deps...)
|
2019-10-29 10:16:15 -06:00
|
|
|
sort.Slice(depList, func(i, j int) bool {
|
|
|
|
return depList[i] < depList[j]
|
2019-07-09 15:52:23 -06:00
|
|
|
})
|
2019-09-27 11:17:59 -06:00
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
deps := make(map[packagePath]*packageHandle)
|
2019-10-29 10:16:15 -06:00
|
|
|
|
2019-10-01 13:21:06 -06:00
|
|
|
// Begin computing the key by getting the depKeys for all dependencies.
|
|
|
|
var depKeys [][]byte
|
2019-10-29 10:16:15 -06:00
|
|
|
for _, depID := range depList {
|
2019-12-04 09:52:39 -07:00
|
|
|
mode := source.ParseExported
|
|
|
|
if s.workspacePackages[depID] {
|
|
|
|
mode = source.ParseFull
|
|
|
|
}
|
|
|
|
depHandle, err := s.packageHandle(ctx, depID, mode)
|
2019-10-01 13:21:06 -06:00
|
|
|
if err != nil {
|
2019-10-20 22:00:20 -06:00
|
|
|
log.Error(ctx, "no dep handle", err, telemetry.Package.Of(depID))
|
2019-10-16 17:09:37 -06:00
|
|
|
|
|
|
|
// One bad dependency should not prevent us from checking the entire package.
|
|
|
|
// Add a special key to mark a bad dependency.
|
|
|
|
depKeys = append(depKeys, []byte(fmt.Sprintf("%s import not found", id)))
|
|
|
|
continue
|
2019-10-01 13:21:06 -06:00
|
|
|
}
|
2019-10-29 10:16:15 -06:00
|
|
|
deps[depHandle.m.pkgPath] = depHandle
|
2019-10-01 13:21:06 -06:00
|
|
|
depKeys = append(depKeys, depHandle.key)
|
|
|
|
}
|
2019-11-29 23:17:57 -07:00
|
|
|
ph.key = checkPackageKey(ph.m.id, ph.compiledGoFiles, m.config, depKeys)
|
|
|
|
return ph, deps, nil
|
2019-05-24 14:03:39 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func checkPackageKey(id packageID, pghs []source.ParseGoHandle, cfg *packages.Config, deps [][]byte) []byte {
|
|
|
|
return []byte(hashContents([]byte(fmt.Sprintf("%s%s%s%s", id, hashParseKeys(pghs), hashConfig(cfg), hashContents(bytes.Join(deps, nil))))))
|
2019-10-01 13:21:06 -06:00
|
|
|
}
|
|
|
|
|
2019-07-09 15:52:23 -06:00
|
|
|
// hashConfig returns the hash for the *packages.Config.
|
|
|
|
func hashConfig(config *packages.Config) string {
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
// Dir, Mode, Env, BuildFlags are the parts of the config that can change.
|
|
|
|
b.WriteString(config.Dir)
|
|
|
|
b.WriteString(string(config.Mode))
|
|
|
|
|
|
|
|
for _, e := range config.Env {
|
|
|
|
b.WriteString(e)
|
2019-03-11 15:14:55 -06:00
|
|
|
}
|
2019-07-09 15:52:23 -06:00
|
|
|
for _, f := range config.BuildFlags {
|
|
|
|
b.WriteString(f)
|
|
|
|
}
|
|
|
|
return hashContents(b.Bytes())
|
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) Check(ctx context.Context) (source.Package, error) {
|
|
|
|
return ph.check(ctx)
|
2019-07-09 15:52:23 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) check(ctx context.Context) (*pkg, error) {
|
|
|
|
v := ph.handle.Get(ctx)
|
2019-07-09 15:52:23 -06:00
|
|
|
if v == nil {
|
2019-11-29 23:17:57 -07:00
|
|
|
return nil, errors.Errorf("no package for %s", ph.m.id)
|
2019-03-04 15:01:39 -07:00
|
|
|
}
|
2019-11-29 23:17:57 -07:00
|
|
|
data := v.(*packageData)
|
2019-07-09 15:52:23 -06:00
|
|
|
return data.pkg, data.err
|
|
|
|
}
|
2019-06-11 09:32:51 -06:00
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) CompiledGoFiles() []source.ParseGoHandle {
|
|
|
|
return ph.compiledGoFiles
|
2019-07-09 15:52:23 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) ID() string {
|
|
|
|
return string(ph.m.id)
|
2019-09-10 15:33:35 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) MissingDependencies() []string {
|
2019-09-23 18:19:50 -06:00
|
|
|
var md []string
|
2019-11-29 23:17:57 -07:00
|
|
|
for i := range ph.m.missingDeps {
|
2019-09-23 18:19:50 -06:00
|
|
|
md = append(md, string(i))
|
|
|
|
}
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) Cached() (source.Package, error) {
|
|
|
|
return ph.cached()
|
2019-09-19 10:39:03 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func (ph *packageHandle) cached() (*pkg, error) {
|
|
|
|
v := ph.handle.Cached()
|
2019-07-09 15:52:23 -06:00
|
|
|
if v == nil {
|
2019-11-29 23:17:57 -07:00
|
|
|
return nil, errors.Errorf("no cached type information for %s", ph.m.pkgPath)
|
2019-03-04 15:45:01 -07:00
|
|
|
}
|
2019-11-29 23:17:57 -07:00
|
|
|
data := v.(*packageData)
|
2019-07-09 15:52:23 -06:00
|
|
|
return data.pkg, data.err
|
|
|
|
}
|
2019-06-11 09:32:51 -06:00
|
|
|
|
2019-11-21 12:54:31 -07:00
|
|
|
func (s *snapshot) parseGoHandles(ctx context.Context, files []span.URI, mode source.ParseMode) ([]source.ParseGoHandle, error) {
|
|
|
|
phs := make([]source.ParseGoHandle, 0, len(files))
|
|
|
|
for _, uri := range files {
|
2019-10-20 22:00:20 -06:00
|
|
|
f, err := s.view.GetFile(ctx, uri)
|
2019-07-09 15:52:23 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-20 22:00:20 -06:00
|
|
|
fh := s.Handle(ctx, f)
|
|
|
|
phs = append(phs, s.view.session.cache.ParseGoHandle(fh, mode))
|
2019-07-09 15:52:23 -06:00
|
|
|
}
|
|
|
|
return phs, nil
|
2019-03-04 15:01:39 -07:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode source.ParseMode, goFiles []source.ParseGoHandle, compiledGoFiles []source.ParseGoHandle, deps map[packagePath]*packageHandle) (*pkg, error) {
|
2019-10-29 10:16:15 -06:00
|
|
|
ctx, done := trace.StartSpan(ctx, "cache.importer.typeCheck", telemetry.Package.Of(m.id))
|
2019-07-09 15:52:23 -06:00
|
|
|
defer done()
|
|
|
|
|
2019-10-20 17:57:03 -06:00
|
|
|
var rawErrors []error
|
2019-10-29 10:16:15 -06:00
|
|
|
for _, err := range m.errors {
|
2019-10-20 17:57:03 -06:00
|
|
|
rawErrors = append(rawErrors, err)
|
|
|
|
}
|
|
|
|
|
2019-05-14 21:04:23 -06:00
|
|
|
pkg := &pkg{
|
2019-11-20 14:15:00 -07:00
|
|
|
id: m.id,
|
|
|
|
pkgPath: m.pkgPath,
|
|
|
|
mode: mode,
|
2019-11-21 12:54:31 -07:00
|
|
|
goFiles: goFiles,
|
|
|
|
compiledGoFiles: compiledGoFiles,
|
2019-11-20 14:15:00 -07:00
|
|
|
imports: make(map[packagePath]*pkg),
|
|
|
|
typesSizes: m.typesSizes,
|
2019-03-06 14:33:47 -07:00
|
|
|
typesInfo: &types.Info{
|
2019-03-04 16:01:51 -07:00
|
|
|
Types: make(map[ast.Expr]types.TypeAndValue),
|
|
|
|
Defs: make(map[*ast.Ident]types.Object),
|
|
|
|
Uses: make(map[*ast.Ident]types.Object),
|
|
|
|
Implicits: make(map[ast.Node]types.Object),
|
|
|
|
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
|
|
|
Scopes: make(map[ast.Node]*types.Scope),
|
|
|
|
},
|
|
|
|
}
|
2019-07-09 15:52:23 -06:00
|
|
|
var (
|
2019-11-20 14:15:00 -07:00
|
|
|
files = make([]*ast.File, len(pkg.compiledGoFiles))
|
|
|
|
parseErrors = make([]error, len(pkg.compiledGoFiles))
|
2019-07-09 15:52:23 -06:00
|
|
|
wg sync.WaitGroup
|
|
|
|
)
|
2019-11-20 14:15:00 -07:00
|
|
|
for i, ph := range pkg.compiledGoFiles {
|
2019-06-21 15:00:02 -06:00
|
|
|
wg.Add(1)
|
|
|
|
go func(i int, ph source.ParseGoHandle) {
|
2019-09-17 09:19:11 -06:00
|
|
|
files[i], _, parseErrors[i], _ = ph.Parse(ctx)
|
2019-11-21 12:54:31 -07:00
|
|
|
wg.Done()
|
2019-06-21 15:00:02 -06:00
|
|
|
}(i, ph)
|
|
|
|
}
|
2019-11-21 12:54:31 -07:00
|
|
|
for _, ph := range pkg.goFiles {
|
|
|
|
wg.Add(1)
|
|
|
|
// We need to parse the non-compiled go files, but we don't care about their errors.
|
|
|
|
go func(ph source.ParseGoHandle) {
|
|
|
|
ph.Parse(ctx)
|
|
|
|
wg.Done()
|
|
|
|
}(ph)
|
|
|
|
}
|
2019-06-21 15:00:02 -06:00
|
|
|
wg.Wait()
|
|
|
|
|
2019-10-20 17:57:03 -06:00
|
|
|
for _, e := range parseErrors {
|
|
|
|
if e != nil {
|
|
|
|
rawErrors = append(rawErrors, e)
|
2019-06-21 15:00:02 -06:00
|
|
|
}
|
2019-03-04 15:01:39 -07:00
|
|
|
}
|
2019-06-11 09:32:51 -06:00
|
|
|
|
2019-08-07 15:49:42 -06:00
|
|
|
var i int
|
|
|
|
for _, f := range files {
|
|
|
|
if f != nil {
|
|
|
|
files[i] = f
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
files = files[:i]
|
|
|
|
|
2019-06-11 12:50:43 -06:00
|
|
|
// Use the default type information for the unsafe package.
|
2019-10-20 17:57:03 -06:00
|
|
|
if pkg.pkgPath == "unsafe" {
|
2019-06-11 12:50:43 -06:00
|
|
|
pkg.types = types.Unsafe
|
|
|
|
} else if len(files) == 0 { // not the unsafe package, no parsed files
|
2019-11-30 00:01:00 -07:00
|
|
|
return nil, errors.Errorf("no parsed files for package %s, expected: %s", pkg.pkgPath, pkg.compiledGoFiles)
|
2019-06-11 12:50:43 -06:00
|
|
|
} else {
|
2019-10-29 10:16:15 -06:00
|
|
|
pkg.types = types.NewPackage(string(m.pkgPath), m.name)
|
2019-04-22 14:04:44 -06:00
|
|
|
}
|
2019-03-11 15:14:55 -06:00
|
|
|
|
2019-03-04 15:01:39 -07:00
|
|
|
cfg := &types.Config{
|
2019-10-20 17:57:03 -06:00
|
|
|
Error: func(e error) {
|
|
|
|
rawErrors = append(rawErrors, e)
|
2019-06-11 12:50:43 -06:00
|
|
|
},
|
2019-10-20 22:00:20 -06:00
|
|
|
Importer: importerFunc(func(pkgPath string) (*types.Package, error) {
|
2019-10-29 10:16:15 -06:00
|
|
|
dep := deps[packagePath(pkgPath)]
|
2019-10-20 22:00:20 -06:00
|
|
|
if dep == nil {
|
2019-10-29 10:16:15 -06:00
|
|
|
return nil, errors.Errorf("no package for import %s", pkgPath)
|
2019-10-20 22:00:20 -06:00
|
|
|
}
|
|
|
|
depPkg, err := dep.check(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
pkg.imports[depPkg.pkgPath] = depPkg
|
|
|
|
return depPkg.types, nil
|
|
|
|
}),
|
2019-03-04 15:01:39 -07:00
|
|
|
}
|
2019-10-29 10:16:15 -06:00
|
|
|
check := types.NewChecker(cfg, fset, pkg.types, pkg.typesInfo)
|
2019-06-21 15:00:02 -06:00
|
|
|
|
2019-09-06 14:32:09 -06:00
|
|
|
// Type checking errors are handled via the config, so ignore them here.
|
|
|
|
_ = check.Files(files)
|
2019-11-11 17:28:40 -07:00
|
|
|
// If the context was cancelled, we may have returned a ton of transient
|
|
|
|
// errors to the type checker. Swallow them.
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
2019-03-04 15:01:39 -07:00
|
|
|
|
2019-12-04 10:56:52 -07:00
|
|
|
// TODO(golang/go#35964): Propagate `go list` errors here when go/packages supports it.
|
|
|
|
for _, e := range rawErrors {
|
|
|
|
srcErr, err := sourceError(ctx, fset, pkg, e)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(ctx, "unable to compute error positions", err, telemetry.Package.Of(pkg.ID()))
|
|
|
|
continue
|
2019-10-20 17:57:03 -06:00
|
|
|
}
|
2019-12-04 10:56:52 -07:00
|
|
|
pkg.errors = append(pkg.errors, srcErr)
|
2019-10-20 17:57:03 -06:00
|
|
|
}
|
2019-05-01 20:46:07 -06:00
|
|
|
return pkg, nil
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:00:20 -06:00
|
|
|
// An importFunc is an implementation of the single-method
|
|
|
|
// types.Importer interface based on a function value.
|
|
|
|
type importerFunc func(path string) (*types.Package, error)
|
|
|
|
|
|
|
|
func (f importerFunc) Import(path string) (*types.Package, error) { return f(path) }
|