Skip to content

Commit

Permalink
internal/lsp: do not allow diff.ApplyEdits to be replaced
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ianthehat committed Oct 2, 2019
1 parent 6fe9ea9 commit 9ade4c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
6 changes: 1 addition & 5 deletions internal/lsp/diff/apply_edits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions internal/lsp/diff/apply_edits_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion internal/lsp/diff/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 9ade4c7

Please sign in to comment.