1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04: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:
Ian Cottrell 2019-09-27 20:01:26 -04:00 committed by Brad Fitzpatrick
parent 91543147e3
commit f7bb6f12f0
3 changed files with 8 additions and 12 deletions

View File

@ -7,11 +7,7 @@ import (
"golang.org/x/tools/internal/span" "golang.org/x/tools/internal/span"
) )
func init() { func ApplyEdits(before string, edits []TextEdit) string {
ApplyEdits = applyEdits
}
func applyEdits(before string, edits []TextEdit) string {
// Preconditions: // Preconditions:
// - all of the edits apply to before // - all of the edits apply to before
// - and all the spans for each TextEdit have the same URI // - and all the spans for each TextEdit have the same URI

View File

@ -1,24 +1,25 @@
package diff package diff_test
import ( import (
"testing" "testing"
"golang.org/x/tools/internal/lsp/diff"
"golang.org/x/tools/internal/span" "golang.org/x/tools/internal/span"
) )
func TestApplyEdits(t *testing.T) { func TestApplyEdits(t *testing.T) {
var testCases = []struct { var testCases = []struct {
before string before string
edits []TextEdit edits []diff.TextEdit
want string want string
}{ }{
{"", nil, ""}, {"", nil, ""},
{"X", []TextEdit{{newSpan(0, 1), "Y"}}, "Y"}, {"X", []diff.TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
{" X ", []TextEdit{{newSpan(1, 2), "Y"}}, " Y "}, {" X ", []diff.TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
{" X X ", []TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "}, {" X X ", []diff.TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
} }
for _, tc := range testCases { 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) t.Errorf("applyEdits(%v, %v): got %v, want %v", tc.before, tc.edits, got, tc.want)
} }
} }

View File

@ -20,7 +20,6 @@ type TextEdit struct {
var ( var (
ComputeEdits func(uri span.URI, before, after string) []TextEdit 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 ToUnified func(from, to string, before string, edits []TextEdit) string
) )