From 912f50adde0ebdacca1c0cd288f88b18b645f731 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Sat, 7 Dec 2019 13:48:38 -0800 Subject: [PATCH] internal/lsp: don't invalidate dependents' metadata When a file is changed, we invalidate various cached data so we re-type check and refetch metadata as needed. Previously when a file changed we would delete the metadata for all transitive reverse dependencies. This broke all-packages-in-workspace features since we could no longer fetch the package handle for packages without metadata. Fix by only deleting metadata for the packages that the file being changed belongs to. It doesn't seem like a package's metadata contains anything that is sensitive to changes in the package's dependencies. Change-Id: I6a2d5df49ecd4d627b37689e48ed48fe78ce658d Reviewed-on: https://go-review.googlesource.com/c/tools/+/210458 Run-TryBot: Muir Manders TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/cache/snapshot.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index e3242ae54c..98fd270e18 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -479,20 +479,16 @@ func (s *snapshot) clone(ctx context.Context, withoutURI span.URI, withoutTypes, withoutTypesIDs := make(map[packageID]struct{}) for k, ids := range s.ids { // Map URIs to IDs for exclusion. - if withoutTypes != nil { - if _, ok := withoutTypes[k]; ok { - for _, id := range ids { - withoutTypesIDs[id] = struct{}{} - } + if _, ok := withoutTypes[k]; ok { + for _, id := range ids { + withoutTypesIDs[id] = struct{}{} } } - if withoutMetadata != nil { - if _, ok := withoutMetadata[k]; ok { - for _, id := range ids { - withoutMetadataIDs[id] = struct{}{} - } - continue + if _, ok := withoutMetadata[k]; ok { + for _, id := range ids { + withoutMetadataIDs[id] = struct{}{} } + continue } result.ids[k] = ids } @@ -608,13 +604,18 @@ func (v *view) invalidateContent(ctx context.Context, f source.File, kind source currentFH := v.session.GetFile(f.URI(), f.Kind()) // Check if the file's package name or imports have changed, - // and if so, invalidate metadata. + // and if so, invalidate this file's packages' metadata. if v.session.cache.shouldLoad(ctx, v.snapshot, originalFH, currentFH) { - withoutMetadata = withoutTypes + for id := range ids { + for _, uri := range v.snapshot.getMetadata(id).compiledGoFiles { + withoutMetadata[uri] = struct{}{} + } - // TODO: If a package's name has changed, - // we should invalidate the metadata for the new package name (if it exists). + // TODO: If a package's name has changed, + // we should invalidate the metadata for the new package name (if it exists). + } } + v.snapshot = v.snapshot.clone(ctx, f.URI(), withoutTypes, withoutMetadata) return true }