From f7bb6f12f04c2ac2e4d81348554844e038fea161 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Fri, 27 Sep 2019 20:01:26 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/diff/apply_edits.go | 6 +----- internal/lsp/diff/apply_edits_test.go | 13 +++++++------ internal/lsp/diff/hooks.go | 1 - 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/internal/lsp/diff/apply_edits.go b/internal/lsp/diff/apply_edits.go index b7a23d1c37..a7ecdf83e1 100644 --- a/internal/lsp/diff/apply_edits.go +++ b/internal/lsp/diff/apply_edits.go @@ -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 diff --git a/internal/lsp/diff/apply_edits_test.go b/internal/lsp/diff/apply_edits_test.go index d9fe85e037..dde5ec0394 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 16c51d98d1..8a830579d3 100644 --- a/internal/lsp/diff/hooks.go +++ b/internal/lsp/diff/hooks.go @@ -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 )