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>
diff --git a/internal/lsp/diff/apply_edits.go b/internal/lsp/diff/apply_edits.go
index b7a23d1..a7ecdf8 100644
--- a/internal/lsp/diff/apply_edits.go
+++ b/internal/lsp/diff/apply_edits.go
@@ -7,11 +7,7 @@
"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
diff --git a/internal/lsp/diff/apply_edits_test.go b/internal/lsp/diff/apply_edits_test.go
index d9fe85e..dde5ec0 100644
--- a/internal/lsp/diff/apply_edits_test.go
+++ b/internal/lsp/diff/apply_edits_test.go
@@ -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)
}
}
diff --git a/internal/lsp/diff/hooks.go b/internal/lsp/diff/hooks.go
index 16c51d9..8a83057 100644
--- a/internal/lsp/diff/hooks.go
+++ b/internal/lsp/diff/hooks.go
@@ -20,7 +20,6 @@
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
)