@@ -1933,6 +1933,12 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
1933
1933
// If a file has been deleted, we must delete metadata for all packages
1934
1934
// containing that file.
1935
1935
workspaceModeChanged := s .workspaceMode () != result .workspaceMode ()
1936
+
1937
+ // Don't keep package metadata for packages that have lost files.
1938
+ //
1939
+ // TODO(rfindley): why not keep invalid metadata in this case? If we
1940
+ // otherwise allow operate on invalid metadata, why not continue to do so,
1941
+ // skipping the missing file?
1936
1942
skipID := map [PackageID ]bool {}
1937
1943
for _ , c := range changes {
1938
1944
if c .exists {
@@ -1967,41 +1973,23 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
1967
1973
addForwardDeps (id )
1968
1974
}
1969
1975
1970
- // Compute which IDs are in the snapshot.
1971
- //
1972
- // TODO(rfindley): this step shouldn't be necessary, since we compute skipID
1973
- // above based on meta.ids.
1974
- deleteInvalidMetadata := forceReloadMetadata || workspaceModeChanged
1975
- idsInSnapshot := map [PackageID ]bool {} // track all known IDs
1976
- for _ , ids := range s .meta .ids {
1977
- for _ , id := range ids {
1978
- if skipID [id ] || deleteInvalidMetadata && idsToInvalidate [id ] {
1979
- continue
1980
- }
1981
- // The ID is not reachable from any workspace package, so it should
1982
- // be deleted.
1983
- if ! reachableID [id ] {
1984
- continue
1985
- }
1986
- idsInSnapshot [id ] = true
1987
- }
1988
- }
1989
- // TODO(adonovan): opt: represent PackageID as an index into a process-global
1990
- // dup-free list of all package names ever seen, then use a bitmap instead of
1991
- // a hash table for "PackageSet" (e.g. idsInSnapshot).
1992
-
1993
1976
// Compute which metadata updates are required. We only need to invalidate
1994
1977
// packages directly containing the affected file, and only if it changed in
1995
1978
// a relevant way.
1996
1979
metadataUpdates := make (map [PackageID ]* KnownMetadata )
1980
+ deleteInvalidMetadata := forceReloadMetadata || workspaceModeChanged
1997
1981
for k , v := range s .meta .metadata {
1998
- if ! idsInSnapshot [k ] {
1999
- // Delete metadata for IDs that are no longer reachable from files
2000
- // in the snapshot.
1982
+ invalidateMetadata := idsToInvalidate [k ]
1983
+ if skipID [k ] || (invalidateMetadata && deleteInvalidMetadata ) {
1984
+ metadataUpdates [k ] = nil
1985
+ continue
1986
+ }
1987
+ // The ID is not reachable from any workspace package, so it should
1988
+ // be deleted.
1989
+ if ! reachableID [k ] {
2001
1990
metadataUpdates [k ] = nil
2002
1991
continue
2003
1992
}
2004
- invalidateMetadata := idsToInvalidate [k ]
2005
1993
valid := v .Valid && ! invalidateMetadata
2006
1994
pkgFilesChanged := v .PkgFilesChanged || changedPkgFiles [k ]
2007
1995
shouldLoad := v .ShouldLoad || invalidateMetadata
0 commit comments