mirror of
https://github.com/golang/go
synced 2024-11-18 23:44:43 -07:00
e8e6be9f45
Change-Id: Ia9e077e6b9cf8a817103d90481768ae99409c574 Reviewed-on: https://go-review.googlesource.com/c/tools/+/183264 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
27 lines
592 B
Go
27 lines
592 B
Go
// +build experimental
|
|
|
|
package source
|
|
|
|
import (
|
|
"go/token"
|
|
"golang.org/x/tools/go/analysis"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func getCodeActions(fset *token.FileSet, diag analysis.Diagnostic) ([]CodeAction, error) {
|
|
var cas []CodeAction
|
|
for _, fix := range diag.SuggestedFixes {
|
|
var ca CodeAction
|
|
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, TextEdit{span, string(te.NewText)})
|
|
}
|
|
cas = append(cas, ca)
|
|
}
|
|
return cas, nil
|
|
}
|