1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:24:39 -07:00
go/internal/lsp/source/suggested_fix_experimental.go
Michael Matloob e8e6be9f45 internal/lsp: plumb suggested fixes through the LSP
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>
2019-06-26 21:02:18 +00:00

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
}