internal/lsp/cache: don't prune unreachable metadata on clone

Package metadata is small; there is no reason not to keep it around, and
pruning it on every clone is needless work.

Change-Id: I9ea73315cc6b673625f0f7defe1fd61c2e1eb123
Reviewed-on: https://go-review.googlesource.com/c/tools/+/373695
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go
index b85b46c..3c46648 100644
--- a/internal/lsp/cache/snapshot.go
+++ b/internal/lsp/cache/snapshot.go
@@ -1945,27 +1945,6 @@
 		}
 	}
 
-	// Collect all of the IDs that are reachable from the workspace packages.
-	// Any unreachable IDs will have their metadata deleted outright.
-	reachableID := map[PackageID]bool{}
-	var addForwardDeps func(PackageID)
-	addForwardDeps = func(id PackageID) {
-		if reachableID[id] {
-			return
-		}
-		reachableID[id] = true
-		m, ok := s.meta.metadata[id]
-		if !ok {
-			return
-		}
-		for _, depID := range m.Deps {
-			addForwardDeps(depID)
-		}
-	}
-	for id := range s.workspacePackages {
-		addForwardDeps(id)
-	}
-
 	// Compute which metadata updates are required. We only need to invalidate
 	// packages directly containing the affected file, and only if it changed in
 	// a relevant way.
@@ -1977,12 +1956,6 @@
 			metadataUpdates[k] = nil
 			continue
 		}
-		// The ID is not reachable from any workspace package, so it should
-		// be deleted.
-		if !reachableID[k] {
-			metadataUpdates[k] = nil
-			continue
-		}
 		valid := v.Valid && !invalidateMetadata
 		pkgFilesChanged := v.PkgFilesChanged || changedPkgFiles[k]
 		shouldLoad := v.ShouldLoad || invalidateMetadata