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 <rfindley@google.com>
This commit is contained in:
Pontus Leitzler 2020-08-22 19:35:59 +02:00 committed by Robert Findley
parent 307de81be3
commit c024452afb
1 changed files with 4 additions and 0 deletions

View File

@ -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)