vscode-go
vscode-go copied to clipboard
Allow for setting a package name when importing a package
Is your feature request related to a problem? Please describe. Oftentimes when I import a package using the "Go: Add Import" feature I'd like to assign a package name to it that is different from the one specified by the imported package. Example:
import corev1 "k8s.io/api/core/v1"
Describe the solution you'd like I'd like to be able to assign a package name when importing a package name so that I don't have to add the import first, then scroll to the top of the file and change the imported package's name (and then scroll back to the original location I was working on).
Describe alternatives you've considered n/a
Additional context n/a
This is currently implemented through gopls's gopls.add_import command.
@marwan-at-work @stamblerre can the command extended to take an additional parameter?
Somewhat related, but I just opened an issue to enhance the "Add Import" flow. This could potentially be a part of?
can the command extended to take an additional parameter?
It certainly can on the gopls side. However, I'm not sure how the UX will look like on the VSCode side. For example:
- Once we prompt the user with a list of packages, do we prompt them again to write a package name? That adds an extra step for those who don't want to rename their package.
- Would we expose a new command that would do the point flow? Something like
Go: Add Renamed Import? - I don't think this is an option but if VSCode can detect selecting an import vs. cmd+selecting an import, then we can have the best of both worlds where selecting an import just adds the import path as is but cmd+selecting an import would prompt the user again to rename the import path before adding it.
Thanks @marwan-at-work
Other options are
- Like 'Go: Add Tags', have a setting that controls the behavior (
go.addTags.promptForTags). But I think we need more flexible option because a user may not always want the prompt. - Include a snippet in a text edit that places cursor before the imported package name. But that will cause the editor focus to change and may not be ideal.
I'd prefer the option 3 (cmd+selecting an item from quickpick), but I cannot find an easy way to implement this yet. The option 2 seems reasonable and users can define a separate key-binding for the new command.
Option 2 sounds clear enough to me as well 👍🏼
Any updates on this branch?