mirror of
https://github.com/golang/go
synced 2024-11-18 16:44:43 -07:00
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 <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
12f59dd68b
commit
78f9822548
24
internal/lsp/cache/view.go
vendored
24
internal/lsp/cache/view.go
vendored
@ -123,19 +123,22 @@ func (v *View) parse(uri source.URI) error {
|
||||
}
|
||||
var foundPkg bool // true if we found the package for uri
|
||||
for _, pkg := range pkgs {
|
||||
// TODO(rstambler): Get real TypeSizes from go/packages (golang.org/issues/30139).
|
||||
pkg.TypesSizes = &types.StdSizes{}
|
||||
|
||||
imp := &importer{
|
||||
entries: make(map[string]*entry),
|
||||
packages: make(map[string]*packages.Package),
|
||||
v: v,
|
||||
topLevelPkgPath: pkg.PkgPath,
|
||||
}
|
||||
|
||||
// TODO(rstambler): Get real TypeSizes from go/packages.
|
||||
pkg.TypesSizes = &types.StdSizes{}
|
||||
|
||||
if err := imp.addImports(pkg); err != nil {
|
||||
if err := imp.addImports(pkg.PkgPath, pkg); err != nil {
|
||||
return err
|
||||
}
|
||||
// Start prefetching direct imports.
|
||||
for importPath := range pkg.Imports {
|
||||
go imp.Import(importPath)
|
||||
}
|
||||
imp.importPackage(pkg.PkgPath)
|
||||
|
||||
// Add every file in this package to our cache.
|
||||
@ -181,13 +184,10 @@ type entry struct {
|
||||
ready chan struct{}
|
||||
}
|
||||
|
||||
func (imp *importer) addImports(pkg *packages.Package) error {
|
||||
imp.packages[pkg.PkgPath] = pkg
|
||||
for _, i := range pkg.Imports {
|
||||
if i.PkgPath == pkg.PkgPath {
|
||||
return fmt.Errorf("import cycle: [%v]", pkg.PkgPath)
|
||||
}
|
||||
if err := imp.addImports(i); err != nil {
|
||||
func (imp *importer) addImports(path string, pkg *packages.Package) error {
|
||||
imp.packages[path] = pkg
|
||||
for importPath, importPkg := range pkg.Imports {
|
||||
if err := imp.addImports(importPath, importPkg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user