Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: handle import aliases automatically #40278

Closed
muirdm opened this issue Jul 17, 2020 · 1 comment
Closed

x/tools/gopls: handle import aliases automatically #40278

muirdm opened this issue Jul 17, 2020 · 1 comment
Labels
Milestone

Comments

@muirdm
Copy link

@muirdm muirdm commented Jul 17, 2020

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:

  1. 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.
  2. 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.
@gopherbot gopherbot added this to the Unreleased milestone Jul 17, 2020
@heschik
Copy link
Contributor

@heschik heschik commented Jul 17, 2020

Think this is a dupe of https://golang.org/issue/36077#issuecomment-567741352. Though goimports currently only scans the current package and gopls could do more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.