Skip to content

Commit 9ade4c7

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 6fe9ea9 commit 9ade4c7

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

internal/lsp/diff/apply_edits.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import (
77
"golang.org/x/tools/internal/span"
88
)
99

10-
func init() {
11-
ApplyEdits = applyEdits
12-
}
13-
14-
func applyEdits(before string, edits []TextEdit) string {
10+
func ApplyEdits(before string, edits []TextEdit) string {
1511
// Preconditions:
1612
// - all of the edits apply to before
1713
// - and all the spans for each TextEdit have the same URI

internal/lsp/diff/apply_edits_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
package diff
1+
package diff_test
22

33
import (
44
"testing"
55

6+
"golang.org/x/tools/internal/lsp/diff"
67
"golang.org/x/tools/internal/span"
78
)
89

910
func TestApplyEdits(t *testing.T) {
1011
var testCases = []struct {
1112
before string
12-
edits []TextEdit
13+
edits []diff.TextEdit
1314
want string
1415
}{
1516
{"", nil, ""},
16-
{"X", []TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
17-
{" X ", []TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
18-
{" X X ", []TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
17+
{"X", []diff.TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
18+
{" X ", []diff.TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
19+
{" X X ", []diff.TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
1920
}
2021
for _, tc := range testCases {
21-
if got := applyEdits(tc.before, tc.edits); got != tc.want {
22+
if got := diff.ApplyEdits(tc.before, tc.edits); got != tc.want {
2223
t.Errorf("applyEdits(%v, %v): got %v, want %v", tc.before, tc.edits, got, tc.want)
2324
}
2425
}

internal/lsp/diff/hooks.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type TextEdit struct {
2020

2121
var (
2222
ComputeEdits func(uri span.URI, before, after string) []TextEdit
23-
ApplyEdits func(before string, edits []TextEdit) string
2423
ToUnified func(from, to string, before string, edits []TextEdit) string
2524
)
2625

0 commit comments

Comments
 (0)