mirror of https://github.com/golang/go.git
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 <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
ecd3fc4348
commit
ca43edf915
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue