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: add a mechanism to control what packages are preferred #46660
Comments
Thanks for the issue. My general feeling on this is that this only matters for unimported completion, for packages with matching members, where the wrong package is scored higher. This should be a very rare occurrence, the benefit is marginal, and such additional configuration has a real cost in both maintenance and configuration complexity. So I don't see this as obviously worthwhile. I wonder if instead we could improve the import path scoring in this case. Can you tell me more about the context? Are you in GOPATH or module mode? Have you imported either of those packages elsewhere in your project? Are either of those modules in your go.mod file? CC @heschi |
In this particular case it looks like both |
I understand. However, I have already wasted hours on this (it causes very strange bugs), so it is certainly in my interests to find some solution that doesn't waste more time. I thought about creating a custom vetter to run with @ramya-rao-a suggested using If gopls had some way to run additional commands when a file was saved, I could use that to run a custom vetter.
Are you saying that I could provide some hints? I'd love to be have some way to tell Or are you saying the authors of |
I work with the aws sdk a lot and often get the wrong imports for boilerplate code I write (copy-paste) over and over again. For example this code block always results in a wrong import for me:
Today this imported:
Where I wanted it to import:
Its extra frustrating because I've never used softlayer for anything but it always wins the imports battle (it is presumably in my mod cache because it is a dependency of some other thirdparty library I use somewhere). If there was a configuration option for specifying preferred imports I would use it for this. |
Sorry this is frustrating. Perhaps this isn't as rare as I originally thought, because of the limited logic of unimported completion.
I think what @heschi is saying is that if unimported completion used the same logic as organize imports, it would take into account which import is used in sibling files (and therefore would be smarter).
From your description, I think this also might be solved by taking sibling imports into account. |
If |
Thanks. Closing this as a duplicate of #36077, which is prioritized for gopls/v1.0.0. |
I want a way to tell gopls, "Whenever I trigger the auto-importer for package
gl
, I specifically wantgithub.com/go-gl/gl/v4.6-core/gl
." Something like:What version of gopls are you using (
gopls version
)?I am using Visual Studio Code and vscode-go.
What did you do?
In a file in a package in which I have not yet imported a
gl
package, I typedgl.stdr
and selectedgl.STATIC_DRAW
from the dropdown.What did you expect to see?
I want to use
import "github.com/go-gl/gl/v4.6-core/gl"
.What did you see instead?
gopls added
import "github.com/go-gl/gl/v2.1/gl"
.The text was updated successfully, but these errors were encountered: