mirror of
https://github.com/golang/go
synced 2024-11-18 23:24:39 -07:00
85edb9ef32
this moves the actual diff algorithm into a different package and then provides hooks so it can be easily replaced with an alternate algorithm. Change-Id: Ia0359f58878493599ea0e0fda8920f21100e16f1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/190898 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
27 lines
641 B
Go
27 lines
641 B
Go
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
|
|
}
|