2019-06-20 14:57:45 -06:00
|
|
|
package source
|
|
|
|
|
2019-08-08 13:30:52 -06:00
|
|
|
import (
|
|
|
|
"go/token"
|
2019-08-19 17:28:08 -06:00
|
|
|
|
2019-08-08 13:30:52 -06:00
|
|
|
"golang.org/x/tools/go/analysis"
|
2019-08-19 17:28:08 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/diff"
|
2019-08-08 13:30:52 -06:00
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
2019-06-20 14:57:45 -06:00
|
|
|
|
|
|
|
func getCodeActions(fset *token.FileSet, diag analysis.Diagnostic) ([]SuggestedFixes, error) {
|
2019-08-08 13:30:52 -06:00
|
|
|
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
|
|
|
|
}
|
2019-08-19 17:28:08 -06:00
|
|
|
ca.Edits = append(ca.Edits, diff.TextEdit{Span: span, NewText: string(te.NewText)})
|
2019-08-08 13:30:52 -06:00
|
|
|
}
|
|
|
|
cas = append(cas, ca)
|
|
|
|
}
|
|
|
|
return cas, nil
|
2019-06-20 14:57:45 -06:00
|
|
|
}
|