Skip to content

Commit

Permalink
internal/lsp/cache: intermediate test variants aren't workspace packages
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
heschi committed Jun 11, 2020
1 parent ecd3fc4 commit ca43edf
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions internal/lsp/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca43edf

Please sign in to comment.