1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:04:40 -07:00
go/internal/lsp/source/suggested_fix.go

27 lines
641 B
Go
Raw Normal View History

package source
import (
"go/token"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/lsp/diff"
"golang.org/x/tools/internal/span"
)
func getCodeActions(fset *token.FileSet, diag analysis.Diagnostic) ([]SuggestedFixes, error) {
var cas []SuggestedFixes
for _, fix := range diag.SuggestedFixes {
var ca SuggestedFixes
ca.Title = fix.Message
for _, te := range fix.TextEdits {
span, err := span.NewRange(fset, te.Pos, te.End).Span()
if err != nil {
return nil, err
}
ca.Edits = append(ca.Edits, diff.TextEdit{Span: span, NewText: string(te.NewText)})
}
cas = append(cas, ca)
}
return cas, nil
}