-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: normalize feature sets of unimported completions and organize imports #36077
Comments
Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here. |
@gopherbot FeatureRequest |
Partly a followup to https://golang.org/cl/204203 -- we should prefer direct deps more than transitive. Also, maybe look into having imports on save do the same sorting. |
Change https://golang.org/cl/212021 mentions this issue: |
As a followup to CL 204203, prefer direct dependencies over indirect. This should improve results for common names like "log" and "errors". Updates golang/go#36077. Change-Id: I3f8cfa070832c2035aec60c4e583ee1c0abf5085 Reviewed-on: https://go-review.googlesource.com/c/tools/+/212021 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Retitling to reflect the remaining work. Unimported completions are missing the "sibling imports" trick. This would be a nice feature. I'm not sure whether to reuse the implementation from the imports package or rewrite it from scratch. Sharing code would be nice, but gopls already has all the parsing done. Just pass all the sibling files to GetPackageExports? Organize Imports is missing the sorting by relevance. This should be easy to plug in to addExternalCandidates, as long as we want it to affect goimports. Sibling imports will take precedence, but that's probably appropriate. |
...except that addExternalCandidates goes to great lengths to return the first usable candidate it finds for speed reasons. It would be very nice to prioritize the scan in the right order, rather than sorting afterward. |
It would be nice if gopls could scan the entire workspace for import aliasing patterns rather than only sibling files. I also imagine it would be convenient if the aliased unimported packages were addressable by both the alias and the package name since the user may or may not anticipate the alias. |
Any movement on this? It's quite an annoying issue. |
Please be specific about what you're seeing and why it's annoying. |
Sorry, I wasn't under the impression that the issue covered more than one bug. What I'm seeing is that import-organization-on-save adds imports that aren't direct dependencies (in For example, It's very annoying when writing tests, because I prefer to just type a bunch of tests and have imports be resolved on save, instead of tediously autocompleting every import. |
Change https://go.dev/cl/623296 mentions this issue: |
In preparation for integrating the newly implemented shared module cache index, carve out a minimal imports.Source interface to be used by FixImports. For now, this interface has a single implementation, wrapping the legacy ProcessEnv abstraction, but in the future we can replace it with an implementation that synthesizes the module cache index with gopls' own view of the workspace. This CL intentionally avoids any refactoring aside from extracting the ProcessEnv-specific logic into a ProcessEnvSource. For golang/go#36077 Change-Id: I189a908c917aba68868b08845880b1f0aa731180 Reviewed-on: https://go-review.googlesource.com/c/tools/+/623296 Reviewed-by: Peter Weinberger <pjw@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Findley <rfindley@google.com>
It it a reasonable temporary solution to take pkg.relevance into account when sorting []byDistanceOrImportPathShortLength{}? Or there is a more reasonable solution , please let me know. I'd like to give it a shot. The scanning order is a very complicated way to new ones like me.
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Can't test on latest release, will update when brew makes go1.13.5 available
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Pasted in some code that referenced a dependency that needed to be imported.
What did you expect to see?
import to be autocompleted for direct dependency
go.company.org/org/lib/v4/errors
What did you see instead?
import autocompleted to transitive dependency
github.com/pkg/errors
Additional Details
This is the
go.mod
of the module I'm working inoutput of
go mod why
The text was updated successfully, but these errors were encountered: