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

Closed
mvdan opened this issue Feb 22, 2021 · 2 comments
Closed
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. 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
@heschi heschi added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Feb 23, 2021
@pjweinb
Copy link

pjweinb commented Feb 12, 2025

Sometime between Feb 2021 and now this has been fixed.

@pjweinb pjweinb closed this as completed Feb 12, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/649315 mentions this issue: gopls/internal: test fixes for some imports bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. 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

6 participants