@@ -123,19 +123,22 @@ func (v *View) parse(uri source.URI) error {
123
123
}
124
124
var foundPkg bool // true if we found the package for uri
125
125
for _ , pkg := range pkgs {
126
+ // TODO(rstambler): Get real TypeSizes from go/packages (golang.org/issues/30139).
127
+ pkg .TypesSizes = & types.StdSizes {}
128
+
126
129
imp := & importer {
127
130
entries : make (map [string ]* entry ),
128
131
packages : make (map [string ]* packages.Package ),
129
132
v : v ,
130
133
topLevelPkgPath : pkg .PkgPath ,
131
134
}
132
-
133
- // TODO(rstambler): Get real TypeSizes from go/packages.
134
- pkg .TypesSizes = & types.StdSizes {}
135
-
136
- if err := imp .addImports (pkg ); err != nil {
135
+ if err := imp .addImports (pkg .PkgPath , pkg ); err != nil {
137
136
return err
138
137
}
138
+ // Start prefetching direct imports.
139
+ for importPath := range pkg .Imports {
140
+ go imp .Import (importPath )
141
+ }
139
142
imp .importPackage (pkg .PkgPath )
140
143
141
144
// Add every file in this package to our cache.
@@ -181,13 +184,10 @@ type entry struct {
181
184
ready chan struct {}
182
185
}
183
186
184
- func (imp * importer ) addImports (pkg * packages.Package ) error {
185
- imp .packages [pkg .PkgPath ] = pkg
186
- for _ , i := range pkg .Imports {
187
- if i .PkgPath == pkg .PkgPath {
188
- return fmt .Errorf ("import cycle: [%v]" , pkg .PkgPath )
189
- }
190
- if err := imp .addImports (i ); err != nil {
187
+ func (imp * importer ) addImports (path string , pkg * packages.Package ) error {
188
+ imp .packages [path ] = pkg
189
+ for importPath , importPkg := range pkg .Imports {
190
+ if err := imp .addImports (importPath , importPkg ); err != nil {
191
191
return err
192
192
}
193
193
}
0 commit comments