gopls/internal/lsp/source: multiline errors from rename

This changes restores the full glory of the multi-line
error messages produced by the gorename tool, which
cite up to three source locations in the explanation
of a renaming conflict. LSP provides no way to preserve
the structure of the error, so we do our best to format
the filename concisely but informatively.

Change-Id: I4e56a818e48f94a19f732f3142917e67869212f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466495
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/gopls/internal/lsp/source/rename.go b/gopls/internal/lsp/source/rename.go
index f56ed40..7b00f88 100644
--- a/gopls/internal/lsp/source/rename.go
+++ b/gopls/internal/lsp/source/rename.go
@@ -35,8 +35,7 @@
 	snapshot           Snapshot
 	refs               []*ReferenceInfo
 	objsToUpdate       map[types.Object]bool
-	hadConflicts       bool
-	errors             string
+	conflicts          []string
 	from, to           string
 	satisfyConstraints map[satisfy.Constraint]bool
 	packages           map[*types.Package]Package // may include additional packages that are a dep of pkg.
@@ -647,13 +646,11 @@
 	// 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 len(r.conflicts) > 0 {
+			// Stop at first error.
+			return nil, fmt.Errorf("%s", strings.Join(r.conflicts, "\n"))
 		}
 	}
-	if r.hadConflicts {
-		return nil, fmt.Errorf("%s", r.errors)
-	}
 
 	changes, err := r.update()
 	if err != nil {