1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:54:39 -07:00
go/internal/lsp/source/suggested_fix.go
Rebecca Stambler 1cc9451822 internal/lsp: distinguish parse errors from actual errors
Parse errors need to be treated separately from actual errors when
parsing a file. Parse errors are treated more like values, whereas
actual errors should not be propagated to the user. This enables us to
delete some of the special handling for context.Canceled errors.

Change-Id: I93a02f22b3f54beccbd6bcf26f04bb8da0202c25
Reviewed-on: https://go-review.googlesource.com/c/tools/+/195997
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-17 21:21:32 +00:00

45 lines
1.0 KiB
Go

package source
import (
"context"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/span"
)
func getCodeActions(ctx context.Context, view View, pkg Package, diag analysis.Diagnostic) ([]SuggestedFix, error) {
var fixes []SuggestedFix
for _, fix := range diag.SuggestedFixes {
var edits []protocol.TextEdit
for _, e := range fix.TextEdits {
posn := view.Session().Cache().FileSet().Position(e.Pos)
ph, _, err := pkg.FindFile(ctx, span.FileURI(posn.Filename))
if err != nil {
return nil, err
}
_, m, _, err := ph.Cached(ctx)
if err != nil {
return nil, err
}
mrng, err := posToRange(ctx, view, m, e.Pos, e.End)
if err != nil {
return nil, err
}
rng, err := mrng.Range()
if err != nil {
return nil, err
}
edits = append(edits, protocol.TextEdit{
Range: rng,
NewText: string(e.NewText),
})
}
fixes = append(fixes, SuggestedFix{
Title: fix.Message,
Edits: edits,
})
}
return fixes, nil
}