mirror of
https://github.com/golang/go
synced 2024-11-18 14:24:44 -07:00
internal/lsp: do not allow diff.ApplyEdits to be replaced
We only need one implementation of this, it must cope with all inputs, and it has no freedom in it's results, so it does not need to be pluggable. Change-Id: I6fec0c339eb288649a670fc3e2cb00c726467e20 Reviewed-on: https://go-review.googlesource.com/c/tools/+/198377 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
91543147e3
commit
f7bb6f12f0
@ -7,11 +7,7 @@ import (
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
func init() {
|
||||
ApplyEdits = applyEdits
|
||||
}
|
||||
|
||||
func applyEdits(before string, edits []TextEdit) string {
|
||||
func ApplyEdits(before string, edits []TextEdit) string {
|
||||
// Preconditions:
|
||||
// - all of the edits apply to before
|
||||
// - and all the spans for each TextEdit have the same URI
|
||||
|
@ -1,24 +1,25 @@
|
||||
package diff
|
||||
package diff_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/diff"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
func TestApplyEdits(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
before string
|
||||
edits []TextEdit
|
||||
edits []diff.TextEdit
|
||||
want string
|
||||
}{
|
||||
{"", nil, ""},
|
||||
{"X", []TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
|
||||
{" X ", []TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
|
||||
{" X X ", []TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
|
||||
{"X", []diff.TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
|
||||
{" X ", []diff.TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
|
||||
{" X X ", []diff.TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
if got := applyEdits(tc.before, tc.edits); got != tc.want {
|
||||
if got := diff.ApplyEdits(tc.before, tc.edits); got != tc.want {
|
||||
t.Errorf("applyEdits(%v, %v): got %v, want %v", tc.before, tc.edits, got, tc.want)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ type TextEdit struct {
|
||||
|
||||
var (
|
||||
ComputeEdits func(uri span.URI, before, after string) []TextEdit
|
||||
ApplyEdits func(before string, edits []TextEdit) string
|
||||
ToUnified func(from, to string, before string, edits []TextEdit) string
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user