Skip to content

Commit e3cedbd

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/server: fix nil panic in findMatchingDiagnostics
Fixes golang/go#71028 Change-Id: Id669625f85066af1ee0c3e26bd557c5603bfb961 Reviewed-on: https://go-review.googlesource.com/c/tools/+/639396 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 649f485 commit e3cedbd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

gopls/internal/server/code_action.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,18 @@ func (s *server) findMatchingDiagnostics(uri protocol.DocumentURI, pd protocol.D
324324
defer s.diagnosticsMu.Unlock()
325325

326326
var sds []*cache.Diagnostic
327-
for _, viewDiags := range s.diagnostics[uri].byView {
328-
for _, sd := range viewDiags.diagnostics {
329-
sameDiagnostic := (pd.Message == strings.TrimSpace(sd.Message) && // extra space may have been trimmed when converting to protocol.Diagnostic
330-
protocol.CompareRange(pd.Range, sd.Range) == 0 &&
331-
pd.Source == string(sd.Source))
327+
if fileDiags := s.diagnostics[uri]; fileDiags != nil {
328+
for _, viewDiags := range fileDiags.byView {
329+
for _, sd := range viewDiags.diagnostics {
330+
// extra space may have been trimmed when
331+
// converting to protocol.Diagnostic
332+
sameDiagnostic := pd.Message == strings.TrimSpace(sd.Message) &&
333+
protocol.CompareRange(pd.Range, sd.Range) == 0 &&
334+
pd.Source == string(sd.Source)
332335

333-
if sameDiagnostic {
334-
sds = append(sds, sd)
336+
if sameDiagnostic {
337+
sds = append(sds, sd)
338+
}
335339
}
336340
}
337341
}

0 commit comments

Comments
 (0)