Skip to content

Commit 78f9822

Browse files
committed
internal/lsp: fix nil pointer exception on vendored packages
Make sure to use the import path in the packages cache, rather than the package path. Also, prefetch dependencies. Change-Id: I0de3942346aa6755dbe904f973aca51d26ba0306 Reviewed-on: https://go-review.googlesource.com/c/162577 Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Cottrell <[email protected]>
1 parent 12f59dd commit 78f9822

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

internal/lsp/cache/view.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,22 @@ func (v *View) parse(uri source.URI) error {
123123
}
124124
var foundPkg bool // true if we found the package for uri
125125
for _, pkg := range pkgs {
126+
// TODO(rstambler): Get real TypeSizes from go/packages (golang.org/issues/30139).
127+
pkg.TypesSizes = &types.StdSizes{}
128+
126129
imp := &importer{
127130
entries: make(map[string]*entry),
128131
packages: make(map[string]*packages.Package),
129132
v: v,
130133
topLevelPkgPath: pkg.PkgPath,
131134
}
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 {
137136
return err
138137
}
138+
// Start prefetching direct imports.
139+
for importPath := range pkg.Imports {
140+
go imp.Import(importPath)
141+
}
139142
imp.importPackage(pkg.PkgPath)
140143

141144
// Add every file in this package to our cache.
@@ -181,13 +184,10 @@ type entry struct {
181184
ready chan struct{}
182185
}
183186

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 {
191191
return err
192192
}
193193
}

0 commit comments

Comments
 (0)