1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04:44 -07:00

internal/lsp: cache file objects for every dependency

Change-Id: I68eedc49a07aa9ba3328a4380e97ed03d1b75749
Reviewed-on: https://go-review.googlesource.com/c/tools/+/170180
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-04-01 10:55:08 -04:00
parent cf22ef0385
commit 4fc9f0bfa5

View File

@ -43,6 +43,7 @@ func (v *View) parse(ctx context.Context, f *File) ([]packages.Error, error) {
imp := &importer{
view: v,
circular: make(map[string]struct{}),
ctx: ctx,
}
// Start prefetching direct imports.
for importPath := range f.meta.children {
@ -53,8 +54,6 @@ func (v *View) parse(ctx context.Context, f *File) ([]packages.Error, error) {
if pkg == nil || pkg.GetTypes() == nil {
return nil, err
}
// Add every file in this package to our cache.
v.cachePackage(ctx, pkg)
// If we still have not found the package for the file, something is wrong.
if f.pkg == nil {
@ -150,7 +149,7 @@ func (v *View) link(pkgPath string, pkg *packages.Package, parent *metadata) *me
m.name = pkg.Name
m.files = pkg.CompiledGoFiles
for _, filename := range m.files {
if f, _ := v.findFile(span.FileURI(filename)); f != nil {
if f, _ := v.getFile(span.FileURI(filename)); f != nil {
f.meta = m
}
}
@ -182,6 +181,8 @@ type importer struct {
// circular maintains the set of previously imported packages.
// If we have seen a package that is already in this map, we have a circular import.
circular map[string]struct{}
ctx context.Context
}
func (imp *importer) Import(pkgPath string) (*types.Package, error) {
@ -259,11 +260,15 @@ func (imp *importer) typeCheck(pkgPath string) (*Package, error) {
Importer: &importer{
view: imp.view,
circular: newCircular,
ctx: imp.ctx,
},
}
check := types.NewChecker(cfg, imp.view.Config.Fset, pkg.types, pkg.typesInfo)
check.Files(pkg.syntax)
// Add every file in this package to our cache.
imp.view.cachePackage(imp.ctx, pkg)
// Set imports of package to correspond to cached packages.
// We lock the package cache, but we shouldn't get any inconsistencies
// because we are still holding the lock on the view.