From d5940c88eb64d71eb1c2d8a638569b1ac7cb66fb Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Fri, 16 Aug 2019 12:23:59 -0400 Subject: [PATCH] internal/lsp: return rename errors for one package only Rename checks all of the packages that may be affected for conflicts. An error in any of them leads to renaming error. Returning errors from multiple packages may be confusing (for example, when there is a test variant of a package and the same error appears twice). This change stops after an error is found and returns that error instead of continuing to search. Change-Id: Ifba1feddbf8829d3aad30309154d578967e05a36 Reviewed-on: https://go-review.googlesource.com/c/tools/+/190416 Run-TryBot: Suzy Mueller TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/source/rename.go | 3 +++ internal/lsp/testdata/rename/bad/bad_test.go.in | 1 + 2 files changed, 4 insertions(+) create mode 100644 internal/lsp/testdata/rename/bad/bad_test.go.in diff --git a/internal/lsp/source/rename.go b/internal/lsp/source/rename.go index 70489620fd..7164f81d71 100644 --- a/internal/lsp/source/rename.go +++ b/internal/lsp/source/rename.go @@ -78,6 +78,9 @@ func (i *IdentifierInfo) Rename(ctx context.Context, newName string) (map[span.U // Check that the renaming of the identifier is ok. for _, ref := range refs { r.check(ref.obj) + if r.hadConflicts { // one error is enough. + break + } } if r.hadConflicts { return nil, errors.Errorf(r.errors) diff --git a/internal/lsp/testdata/rename/bad/bad_test.go.in b/internal/lsp/testdata/rename/bad/bad_test.go.in new file mode 100644 index 0000000000..e695db14be --- /dev/null +++ b/internal/lsp/testdata/rename/bad/bad_test.go.in @@ -0,0 +1 @@ +package bad \ No newline at end of file