1
0
mirror of https://github.com/golang/go synced 2024-11-05 11:36:10 -07:00

internal/lsp/cache: handle a few possible panics in PackageStats

Change-Id: I50dbe8bf7d801e7325bdbe413368e85779511d85
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240183
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rebecca Stambler 2020-06-26 17:18:10 -04:00
parent aa3d50130b
commit 4bdfe1a3b7

View File

@ -176,11 +176,21 @@ func (c *Cache) PackageStats(withNames bool) template.HTML {
switch k.(type) { switch k.(type) {
case packageHandleKey: case packageHandleKey:
v := v.(*packageData) v := v.(*packageData)
if v.pkg == nil {
break
}
var typsCost, typInfoCost int64
if v.pkg.types != nil {
typsCost = typesCost(v.pkg.types.Scope())
}
if v.pkg.typesInfo != nil {
typInfoCost = typesInfoCost(v.pkg.typesInfo)
}
stat := packageStat{ stat := packageStat{
id: v.pkg.id, id: v.pkg.id,
mode: v.pkg.mode, mode: v.pkg.mode,
types: typesCost(v.pkg.types.Scope()), types: typsCost,
typesInfo: typesInfoCost(v.pkg.typesInfo), typesInfo: typInfoCost,
} }
for _, f := range v.pkg.compiledGoFiles { for _, f := range v.pkg.compiledGoFiles {
fvi := f.handle.Cached() fvi := f.handle.Cached()