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: reuse named imports from other packages in the current module #44510

Open
mvdan opened this issue Feb 22, 2021 · 0 comments
Open
Labels
FeatureRequest gopls/imports gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@mvdan
Copy link
Member

mvdan commented Feb 22, 2021

Take the following dummy module with two simple Go files:

-- go.mod --
module test

go 1.14
-- foo/foo.go --
package main

import strs "strings"

var _ = strs.Count
-- bar/bar.go --
package main

var _ = strs.Builder

If I open both Go files with vim+govim+gopls and save, I would expect bar.go to gain import strs "strings", mimicking the other package in the same module. This works fine if both files are in the same package, but not if they are in different packages.

Assuming that gopls already collects information about all packages in the current main module, I think it should also be able to pick up named imports from other packages to try to be more helpful when adding imports.

In particular, this came up while writing tests in a new package with import qt "github.com/frankban/quicktest".

cc @heschik @stamblerre @myitcv @danp

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 22, 2021
@gopherbot gopherbot added this to the Unreleased milestone Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls/imports gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants