-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp/cache: derive workspace packages from metadata
Now that we preserve stale metadata, we can derive workspace packages entirely from known metadata and files. This consolidates the logic to compute workspace packages into a single location, which can be invoked whenever metadata changes (via load or invalidation in clone). Additionally: - Precompute 'HasWorkspaceFiles' when loading metadata. This value should never change for a given Metadata, and our view.contains func is actually quite slow due to evaluating symlinks. - Track 'PkgFilesChanged' on KnownMetadata, since we don't include packages whose package name has changed in our workspace. Also introduce a few debug helpers, so that we can leave some instrumentation in critical functions. For golang/go#45686 Change-Id: I2c994a1e8ca05c3c42f67bd2f4519bea5095c54c Reviewed-on: https://go-review.googlesource.com/c/tools/+/340735 Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]>
- Loading branch information
Showing
4 changed files
with
153 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cache | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sort" | ||
) | ||
|
||
// This file contains helpers that can be used to instrument code while | ||
// debugging. | ||
|
||
// debugEnabled toggles the helpers below. | ||
const debugEnabled = false | ||
|
||
// If debugEnabled is true, debugf formats its arguments and prints to stderr. | ||
// If debugEnabled is false, it is a no-op. | ||
func debugf(format string, args ...interface{}) { | ||
if !debugEnabled { | ||
return | ||
} | ||
if false { | ||
fmt.Sprintf(format, args...) // encourage vet to validate format strings | ||
} | ||
fmt.Fprintf(os.Stderr, ">>> "+format+"\n", args...) | ||
} | ||
|
||
// If debugEnabled is true, dumpWorkspace prints a summary of workspace | ||
// packages to stderr. If debugEnabled is false, it is a no-op. | ||
func (s *snapshot) dumpWorkspace(context string) { | ||
if !debugEnabled { | ||
return | ||
} | ||
|
||
debugf("workspace (after %s):", context) | ||
var ids []PackageID | ||
for id := range s.workspacePackages { | ||
ids = append(ids, id) | ||
} | ||
|
||
sort.Slice(ids, func(i, j int) bool { | ||
return ids[i] < ids[j] | ||
}) | ||
|
||
for _, id := range ids { | ||
pkgPath := s.workspacePackages[id] | ||
_, ok := s.meta.metadata[id] | ||
debugf(" %s:%s (metadata: %t)", id, pkgPath, ok) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters