Closed
Description
It is annoying when your file needs to import multiple packages with the same name. Tooling often offers no relief from having to manually import and alias the second package. It would be nice if gopls could help by automatically adding package import aliases when possible and appropriate.
I propose we do something like this to start:
- When loading packages we keep track of package aliases we see in existing imports. We could store the alias counts by containing package to avoid over counting as a package gets re-type checked.
- When offering unimported package completions, if a candidate package's name is already used by an existing import in the file, automatically include the "best" alias we have seen elsewhere for that package. We probably want to make the aliased unimported package addressable by both the alias and the package name since the user may or may not anticipate the alias.