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

internal/lsp/cache: use a map to track package paths to reload

I could've sworn I'd already submitted this CL earlier. We've been
sending duplicate package paths to go/packages for no reason.

Updates golang/go#40690

Change-Id: I4c0d082a71e53df12991341b015e0ce8f504c318
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248403
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rebecca Stambler 2020-08-13 19:19:01 -04:00
parent cd238244dd
commit c4923e618c

View File

@ -696,21 +696,25 @@ func (s *snapshot) reloadWorkspace(ctx context.Context) error {
// See which of the workspace packages are missing metadata.
s.mu.Lock()
var pkgPaths []interface{}
pkgPathSet := map[packagePath]struct{}{}
for id, pkgPath := range s.workspacePackages {
// Don't try to reload "command-line-arguments" directly.
if pkgPath == "command-line-arguments" {
continue
}
if s.metadata[id] == nil {
pkgPaths = append(pkgPaths, pkgPath)
pkgPathSet[pkgPath] = struct{}{}
}
}
s.mu.Unlock()
if len(pkgPaths) == 0 {
if len(pkgPathSet) == 0 {
return nil
}
var pkgPaths []interface{}
for pkgPath := range pkgPathSet {
pkgPaths = append(pkgPaths, pkgPath)
}
return s.load(ctx, pkgPaths...)
}