mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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>
This commit is contained in:
parent
ea203083f5
commit
689d0f08e6
@ -643,6 +643,13 @@ func getCandidatePkgs(pkgName, filename string, env *ProcessEnv) ([]*pkg, error)
|
|||||||
return result, nil
|
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.
|
// getAllCandidates gets all of the candidates to be imported, regardless of if they are needed.
|
||||||
func getAllCandidates(filename string, env *ProcessEnv) ([]ImportFix, error) {
|
func getAllCandidates(filename string, env *ProcessEnv) ([]ImportFix, error) {
|
||||||
pkgs, err := getCandidatePkgs("", filename, env)
|
pkgs, err := getCandidatePkgs("", filename, env)
|
||||||
@ -654,6 +661,7 @@ func getAllCandidates(filename string, env *ProcessEnv) ([]ImportFix, error) {
|
|||||||
result = append(result, ImportFix{
|
result = append(result, ImportFix{
|
||||||
StmtInfo: ImportInfo{
|
StmtInfo: ImportInfo{
|
||||||
ImportPath: pkg.importPathShort,
|
ImportPath: pkg.importPathShort,
|
||||||
|
Name: candidateImportName(pkg),
|
||||||
},
|
},
|
||||||
IdentName: pkg.packageName,
|
IdentName: pkg.packageName,
|
||||||
FixType: AddImport,
|
FixType: AddImport,
|
||||||
@ -679,6 +687,7 @@ func getPackageExports(completePackage, filename string, env *ProcessEnv) ([]Pac
|
|||||||
fix := &ImportFix{
|
fix := &ImportFix{
|
||||||
StmtInfo: ImportInfo{
|
StmtInfo: ImportInfo{
|
||||||
ImportPath: pkg.importPathShort,
|
ImportPath: pkg.importPathShort,
|
||||||
|
Name: candidateImportName(pkg),
|
||||||
},
|
},
|
||||||
IdentName: pkg.packageName,
|
IdentName: pkg.packageName,
|
||||||
FixType: AddImport,
|
FixType: AddImport,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user