mirror of
https://github.com/golang/go
synced 2024-11-19 03:04:42 -07:00
2ca718005c
Change-Id: I8b454dd8c59839468ecfcb19b7edfa659e386b57 Reviewed-on: https://go-review.googlesource.com/c/tools/+/193957 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
35 lines
738 B
Go
35 lines
738 B
Go
package source
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
)
|
|
|
|
func getCodeActions(ctx context.Context, view View, diag analysis.Diagnostic) ([]SuggestedFix, error) {
|
|
var fixes []SuggestedFix
|
|
for _, fix := range diag.SuggestedFixes {
|
|
var edits []protocol.TextEdit
|
|
for _, e := range fix.TextEdits {
|
|
mrng, err := posToRange(ctx, view, 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
|
|
}
|