gopls/internal/lsp: split ActivePackages
ActivePackages used to compute a set of packages, then
type check them all, even though many clients need only
metadata. This change replaces it by ActiveMetadata,
which returns only metadata for the set of packages,
and exposes the LoadPackages operation allowing callers
to load only the subset they actually need.
Details:
- Snapshot.TypeCheck method is exposed.
- Snapshot.DiagnosePackage now takes a PackageID,
and calls for typechecking itself. Similarly Server.diagnosePkg.
- source.Analyze now takes a PackageID, noot Package
(which it previously used only for its ID).
- GCOptimizationDetails accepts a Metadata, not a Package.
- workspaceMetadata replaces workspacePackageID, activePackageIDs.
- Combined the two loops in Server.diagnoseChangedFiles,
and parallelized the diagnose calls in moddiagnostics,
to ensure that type checking happens in parallel.
Change-Id: Id0383a678ce45447f3313d1426e3f9b96050eaa1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/456275
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/lsp/cache/mod_tidy.go b/gopls/internal/lsp/cache/mod_tidy.go
index 9495f3f..fa30df1 100644
--- a/gopls/internal/lsp/cache/mod_tidy.go
+++ b/gopls/internal/lsp/cache/mod_tidy.go
@@ -192,12 +192,7 @@
// Add diagnostics for missing modules anywhere they are imported in the
// workspace.
// TODO(adonovan): opt: opportunities for parallelism abound.
- for _, id := range snapshot.workspacePackageIDs() {
- m := snapshot.Metadata(id)
- if m == nil {
- return nil, fmt.Errorf("no metadata for %s", id)
- }
-
+ for _, m := range snapshot.workspaceMetadata() {
// Read both lists of files of this package, in parallel.
goFiles, compiledGoFiles, err := readGoFiles(ctx, snapshot, m)
if err != nil {