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 <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/source/rename.go b/internal/lsp/source/rename.go
index 7048962..7164f81 100644
--- a/internal/lsp/source/rename.go
+++ b/internal/lsp/source/rename.go
@@ -78,6 +78,9 @@
 	// 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 0000000..e695db1
--- /dev/null
+++ b/internal/lsp/testdata/rename/bad/bad_test.go.in
@@ -0,0 +1 @@
+package bad
\ No newline at end of file