From 7ad9cd8f3189de72271433f77754bded3c93f479 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 16 Jan 2020 17:13:03 -0500 Subject: [PATCH] internal/lsp/cache: invalidate metadata for x_tests and test variants Invalidating metadata for reverse dependencies isn't necessary, except for in the case of test variants and x_tests. An example: The only way to reload the metadata for "golang.org/x/tools/internal/lsp/cache [golang.org/x/tools/internal/lsp/source.test]" is by reloading "golang.org/x/tools/internal/lsp/source" with "[-test -deps]". That means we have to invalidate the metadata for that "golang.org/x/tools/internal/lsp/source_test" when we invalidating "golang.org/x/tools/internal/lsp/cache". Fixes golang/go#36165 Change-Id: Iff0e03a7a46158fbdafaffa091f90ca434700a97 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215117 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/cache/snapshot.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 95b20bc3696..d06253dd61d 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -666,6 +666,22 @@ func (s *snapshot) clone(ctx context.Context, withoutURI span.URI) *snapshot { for id := range directIDs { addRevDeps(id) } + // Invalidate metadata for the transitive dependencies, + // if they are x_tests and test variants. + // + // An example: + // + // The only way to reload the metadata for + // golang.org/x/tools/internal/lsp/cache [golang.org/x/tools/internal/lsp/source.test] + // is by reloading golang.org/x/tools/internal/lsp/source. + // That means we have to invalidate the metadata for + // golang.org/x/tools/internal/lsp/source_test when invalidating metadata for + // golang.org/x/tools/internal/lsp/cache. + for id := range transitiveIDs { + if m := s.metadata[id]; m != nil && m.forTest != "" { + directIDs[id] = struct{}{} + } + } result := &snapshot{ id: s.id + 1,