mirror of
https://github.com/golang/go
synced 2024-11-18 18:34:40 -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:
parent
cf22ef0385
commit
4fc9f0bfa5
11
internal/lsp/cache/check.go
vendored
11
internal/lsp/cache/check.go
vendored
@ -43,6 +43,7 @@ func (v *View) parse(ctx context.Context, f *File) ([]packages.Error, error) {
|
|||||||
imp := &importer{
|
imp := &importer{
|
||||||
view: v,
|
view: v,
|
||||||
circular: make(map[string]struct{}),
|
circular: make(map[string]struct{}),
|
||||||
|
ctx: ctx,
|
||||||
}
|
}
|
||||||
// Start prefetching direct imports.
|
// Start prefetching direct imports.
|
||||||
for importPath := range f.meta.children {
|
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 {
|
if pkg == nil || pkg.GetTypes() == nil {
|
||||||
return nil, err
|
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 we still have not found the package for the file, something is wrong.
|
||||||
if f.pkg == nil {
|
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.name = pkg.Name
|
||||||
m.files = pkg.CompiledGoFiles
|
m.files = pkg.CompiledGoFiles
|
||||||
for _, filename := range m.files {
|
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
|
f.meta = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,6 +181,8 @@ type importer struct {
|
|||||||
// circular maintains the set of previously imported packages.
|
// 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.
|
// If we have seen a package that is already in this map, we have a circular import.
|
||||||
circular map[string]struct{}
|
circular map[string]struct{}
|
||||||
|
|
||||||
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (imp *importer) Import(pkgPath string) (*types.Package, error) {
|
func (imp *importer) Import(pkgPath string) (*types.Package, error) {
|
||||||
@ -259,11 +260,15 @@ func (imp *importer) typeCheck(pkgPath string) (*Package, error) {
|
|||||||
Importer: &importer{
|
Importer: &importer{
|
||||||
view: imp.view,
|
view: imp.view,
|
||||||
circular: newCircular,
|
circular: newCircular,
|
||||||
|
ctx: imp.ctx,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
check := types.NewChecker(cfg, imp.view.Config.Fset, pkg.types, pkg.typesInfo)
|
check := types.NewChecker(cfg, imp.view.Config.Fset, pkg.types, pkg.typesInfo)
|
||||||
check.Files(pkg.syntax)
|
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.
|
// Set imports of package to correspond to cached packages.
|
||||||
// We lock the package cache, but we shouldn't get any inconsistencies
|
// We lock the package cache, but we shouldn't get any inconsistencies
|
||||||
// because we are still holding the lock on the view.
|
// because we are still holding the lock on the view.
|
||||||
|
Loading…
Reference in New Issue
Block a user