From c024452afbcdebb4a0fbe1bb0eaea0d2dbff835b Mon Sep 17 00:00:00 2001 From: Pontus Leitzler Date: Sat, 22 Aug 2020 19:35:59 +0200 Subject: [PATCH] internal/lsp: don't panic if there are no suggested fixes If an analyzer doesn't return error, and doesn't have any suggested fixs either gopls panics. Return an empty set of edits instead. Change-Id: I1cd812fedcbd2ddc01229f48c0cc4467ee3f0105 Reviewed-on: https://go-review.googlesource.com/c/tools/+/249998 Reviewed-by: Robert Findley --- internal/lsp/source/command.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lsp/source/command.go b/internal/lsp/source/command.go index fb178c72ba..0de8cb57e2 100644 --- a/internal/lsp/source/command.go +++ b/internal/lsp/source/command.go @@ -171,6 +171,10 @@ func (c *Command) SuggestedFix(ctx context.Context, snapshot Snapshot, fh Versio if err != nil { return nil, err } + if fix == nil { + return nil, nil + } + var edits []protocol.TextDocumentEdit for _, edit := range fix.TextEdits { rng := span.NewRange(fset, edit.Pos, edit.End)