From 4fc9f0bfa59af25ec747132b66fc7887a8c34490 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 1 Apr 2019 10:55:08 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/lsp/cache/check.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index 1fdbf4a0..1b5e5ca7 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -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.