internal/lsp: fix nil pointer in 'go mod why' logic
Fixes golang/go#37977
Change-Id: I125c7900e8ee7975f179ea68333ea347b9bfa9e8
GitHub-Last-Rev: 69b71b7853dedc1dc42e96059aa693a4b8652062
GitHub-Pull-Request: golang/tools#217
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224591
Reviewed-by: Rohan Challa <rohan@golang.org>
diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go
index c532d89..af4fd8d 100644
--- a/internal/lsp/cache/mod.go
+++ b/internal/lsp/cache/mod.go
@@ -225,10 +225,10 @@
return err
}
whyList := strings.Split(stdout.String(), "\n\n")
- if len(whyList) <= 1 || len(whyList) > len(data.origParsedFile.Require) {
+ if len(whyList) <= 1 || len(whyList) != len(data.origParsedFile.Require) {
return nil
}
- data.why = make(map[string]string)
+ data.why = make(map[string]string, len(data.origParsedFile.Require))
for i, req := range data.origParsedFile.Require {
data.why[req.Mod.Path] = whyList[i]
}