@@ -39,34 +39,6 @@ type Metadata struct {
39
39
40
40
// Config is the *packages.Config associated with the loaded package.
41
41
Config * packages.Config
42
-
43
- // IsIntermediateTestVariant reports whether the given package is an
44
- // intermediate test variant, e.g.
45
- // "golang.org/x/tools/gopls/internal/lsp/cache [golang.org/x/tools/gopls/internal/lsp/source.test]".
46
- //
47
- // Such test variants arise when an x_test package (in this case source_test)
48
- // imports a package (in this case cache) that itself imports the the
49
- // non-x_test package (in this case source).
50
- //
51
- // This is done so that the forward transitive closure of source_test has
52
- // only one package for the "golang.org/x/tools/gopls/internal/lsp/source" import.
53
- // The intermediate test variant exists to hold the test variant import:
54
- //
55
- // golang.org/x/tools/gopls/internal/lsp/source_test [golang.org/x/tools/gopls/internal/lsp/source.test]
56
- // | "golang.org/x/tools/gopls/internal/lsp/cache" -> golang.org/x/tools/gopls/internal/lsp/cache [golang.org/x/tools/gopls/internal/lsp/source.test]
57
- // | "golang.org/x/tools/gopls/internal/lsp/source" -> golang.org/x/tools/gopls/internal/lsp/source [golang.org/x/tools/gopls/internal/lsp/source.test]
58
- // | ...
59
- //
60
- // golang.org/x/tools/gopls/internal/lsp/cache [golang.org/x/tools/gopls/internal/lsp/source.test]
61
- // | "golang.org/x/tools/gopls/internal/lsp/source" -> golang.org/x/tools/gopls/internal/lsp/source [golang.org/x/tools/gopls/internal/lsp/source.test]
62
- // | ...
63
- //
64
- // We filter these variants out in certain places. For example, there is
65
- // generally no reason to run diagnostics or analysis on them.
66
- //
67
- // TODO(rfindley): this can probably just be a method, since it is derived
68
- // from other fields.
69
- IsIntermediateTestVariant bool
70
42
}
71
43
72
44
// Name implements the source.Metadata interface.
@@ -79,6 +51,40 @@ func (m *Metadata) PackagePath() string {
79
51
return string (m .PkgPath )
80
52
}
81
53
54
+ // IsIntermediateTestVariant reports whether the given package is an
55
+ // intermediate test variant, e.g. "net/http [net/url.test]".
56
+ //
57
+ // Such test variants arise when an x_test package (in this case net/url_test)
58
+ // imports a package (in this case net/http) that itself imports the the
59
+ // non-x_test package (in this case net/url).
60
+ //
61
+ // This is done so that the forward transitive closure of net/url_test has
62
+ // only one package for the "net/url" import.
63
+ // The intermediate test variant exists to hold the test variant import:
64
+ //
65
+ // net/url_test [net/url.test]
66
+ //
67
+ // | "net/http" -> net/http [net/url.test]
68
+ // | "net/url" -> net/url [net/url.test]
69
+ // | ...
70
+ //
71
+ // net/http [net/url.test]
72
+ //
73
+ // | "net/url" -> net/url [net/url.test]
74
+ // | ...
75
+ //
76
+ // This restriction propagates throughout the import graph of net/http: for
77
+ // every package imported by net/http that imports net/url, there must be an
78
+ // intermediate test variant that instead imports "net/url [net/url.test]".
79
+ //
80
+ // As one can see from the example of net/url and net/http, intermediate test
81
+ // variants can result in many additional packages that are essentially (but
82
+ // not quite) identical. For this reason, we filter these variants wherever
83
+ // possible.
84
+ func (m * Metadata ) IsIntermediateTestVariant () bool {
85
+ return m .ForTest != "" && m .ForTest != m .PkgPath && m .ForTest + "_test" != m .PkgPath
86
+ }
87
+
82
88
// ModuleInfo implements the source.Metadata interface.
83
89
func (m * Metadata ) ModuleInfo () * packages.Module {
84
90
return m .Module
0 commit comments