internal/imports: set import names on completion candidates

I forgot to set .Name on completion candidates. That meant that if the
package name didn't match the import path, you'd first get an import
without a name, then it would be added when you organized imports.

Change-Id: Ic374de872324effa6bc04c1440c659d7a182d17f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205503
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
(cherry picked from commit 689d0f08e67ae0c77c260e137ac6a3729498c92f)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205660
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/imports/fix.go b/internal/imports/fix.go
index 916ddf3..cdaa57b 100644
--- a/internal/imports/fix.go
+++ b/internal/imports/fix.go
@@ -643,6 +643,13 @@
 	return result, nil
 }
 
+func candidateImportName(pkg *pkg) string {
+	if importPathToAssumedName(pkg.importPathShort) != pkg.packageName {
+		return pkg.packageName
+	}
+	return ""
+}
+
 // getAllCandidates gets all of the candidates to be imported, regardless of if they are needed.
 func getAllCandidates(filename string, env *ProcessEnv) ([]ImportFix, error) {
 	pkgs, err := getCandidatePkgs("", filename, env)
@@ -654,6 +661,7 @@
 		result = append(result, ImportFix{
 			StmtInfo: ImportInfo{
 				ImportPath: pkg.importPathShort,
+				Name:       candidateImportName(pkg),
 			},
 			IdentName: pkg.packageName,
 			FixType:   AddImport,
@@ -679,6 +687,7 @@
 		fix := &ImportFix{
 			StmtInfo: ImportInfo{
 				ImportPath: pkg.importPathShort,
+				Name:       candidateImportName(pkg),
 			},
 			IdentName: pkg.packageName,
 			FixType:   AddImport,