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

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 <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Muir Manders 2019-12-07 13:48:38 -08:00 committed by Rebecca Stambler
parent 98df123772
commit 912f50adde

View File

@ -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
}