From 24ca011bb20fb526b168d3c3d0a7fac0b14a161b Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 26 Jun 2020 17:18:10 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick (cherry picked from commit 4bdfe1a3b708753b8c1d684e45901a1ab70aea35) Reviewed-on: https://go-review.googlesource.com/c/tools/+/240542 Reviewed-by: Robert Findley --- internal/lsp/cache/cache.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/lsp/cache/cache.go b/internal/lsp/cache/cache.go index 8a72479d0fe..0c08a68ed08 100644 --- a/internal/lsp/cache/cache.go +++ b/internal/lsp/cache/cache.go @@ -176,11 +176,21 @@ func (c *Cache) PackageStats(withNames bool) template.HTML { switch k.(type) { case packageHandleKey: 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{ id: v.pkg.id, mode: v.pkg.mode, - types: typesCost(v.pkg.types.Scope()), - typesInfo: typesInfoCost(v.pkg.typesInfo), + types: typsCost, + typesInfo: typInfoCost, } for _, f := range v.pkg.compiledGoFiles { fvi := f.handle.Cached()