From ca43edf915e9a494d684259feab8acdb52632eb9 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 3 Jun 2020 21:13:43 -0400 Subject: [PATCH] internal/lsp/cache: intermediate test variants aren't workspace packages When you write a test in (say) the fmt package, you get a test variant augmented with the test files. In many cases you also get test variants of the things the fmt package depends on. The primary test variant, (fmt [fmt.test]) is interesting to us, because it contains the tests. But the intermediate variants (testing [fmt.test]) aren't -- the user can only get to them indirectly. We certainly don't need to fully parse them. Treat intermediate test variants as non-workspace packages. This doesn't accomplish much yet but paves the way for later optimizations. Updates golang/go#36943. Change-Id: I1a20abcd2d67767f07132a75a20f098be6f19a76 Reviewed-on: https://go-review.googlesource.com/c/tools/+/236397 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/cache/load.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 59aa042691..87cbf1910b 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -212,16 +212,21 @@ func (s *snapshot) setMetadata(ctx context.Context, pkgPath packagePath, pkg *pa // Set the workspace packages. If any of the package's files belong to the // view, then the package is considered to be a workspace package. for _, uri := range append(m.compiledGoFiles, m.goFiles...) { - // If the package's files are in this view, mark it as a workspace package. - if s.view.contains(uri) { - // A test variant of a package can only be loaded directly by loading - // the non-test variant with -test. Track the import path of the non-test variant. - if m.forTest != "" { - s.workspacePackages[m.id] = m.forTest - } else { - s.workspacePackages[m.id] = pkgPath - } - break + if !s.view.contains(uri) { + continue + } + + // The package's files are in this view. It may be a workspace package. + switch m.forTest { + case "": + // A normal package. + s.workspacePackages[m.id] = pkgPath + case m.pkgPath: + // The test variant of some workspace package. To load it, we need to + // load the non-test variant with -test. + s.workspacePackages[m.id] = m.forTest + default: + // A test variant of some intermediate package. We don't care about it. } } return m, nil