Open JamyDev opened 1 year ago
Can you share which gopackagesdriver
you are using.
The default gopackage driver go list
handles this case by using overlay.
https://pkg.go.dev/golang.org/x/tools/go/packages#Config
Is it possible to make your gopackagesdriver recognize the overlay info?
@golang/tools-team I think we need documentation on gopackagesdriver https://github.com/golang/go/issues/34341
We use the rules_go one. I'll have a look at overlay info and see how to support it in the rules_go driver
We discussed this a bit more in our team meeting, and decided it would probably be very difficult to support this in the bazel driver (based on our understanding of bazel).
So we'll leave this open: it would be nice to fix, but unlikely to get prioritized any time soon. The work to implement this would be approximately:
cache.snapshot.clone
while the user types....but this will be very tricky to implement, and even after implemented may have to a subtly confusing UX.
@findleyr Hello, What is the status of this support programme? We had a similar problem when we implemented a packagedriver ourselves and he would dynamically generate code to return package information. but because of caching issues, there is no way to get the latest generated code. Is there a recommended solution? Apart from rebooting
@li-jin-gou I think this issue may have been superseded by #68002. I plan to implement #68002 this year. It is currently targetting the v0.17.0 release, which is tentatively planned for October.
@findleyr Hello, What is the status of this support programme? We had a similar problem when we implemented a packagedriver ourselves and he would dynamically generate code to return package information. but because of caching issues, there is no way to get the latest generated code. Is there a recommended solution? Apart from rebooting
I have a similar problem to him. After my local dependencies using gopackagesdriver are changed, I hope gopls can get the latest data in time. Is there any gopls command that can achieve this? Or is there any other better way?
Thanks, until then we can move forward with the programme of trying to restart gopls. @findleyr
FWIW at Uber we did 2 things to fix this:
FWIW at Uber we did 2 things to fix this:
- Support overlays on our internal driver. The overlay content contains the newly added import which fixes the initial issue (assuming you have some way of resolving said import without your dependency manager).
- Added a "reload Imports" codelens above the imports section. Clicking this invalidates the target in our cache, and then slightly modifies the imports (adds a space at the front of the first import and removes it right after). The imports modification triggers gopls to request the imports from the packages driver.
thanks
FWIW at Uber we did 2 things to fix this:
- Support overlays on our internal driver. The overlay content contains the newly added import which fixes the initial issue (assuming you have some way of resolving said import without your dependency manager).
- Added a "reload Imports" codelens above the imports section. Clicking this invalidates the target in our cache, and then slightly modifies the imports (adds a space at the front of the first import and removes it right after). The imports modification triggers gopls to request the imports from the packages driver. @li-jin-gou @ViolaPioggia
sorry sir. In our case, the content of *packages.DriverResponse is unchanged, but the content of the file it maps to has changed. So the IDE is not aware of the fact that the prompts are no longer correct due to a change in the file
{
"ID": "service1/hello",
"Name": "hello",
"PkgPath": "rgo/service1/kitex_gen/hello",
"GoFiles": [
"/root/cache/service1/hello/hello.go"
],
"CompiledGoFiles": [
"/root/cache/service1/hello/hello.go"
],
"Imports": {
"context": "context",
"fmt": "fmt"
}
},
In fact it really doesn't describe whether or not the specifics of the file change. Have you ever had this problem? @JamyDev
Dependencies may have been added or the original dependency code may have changed.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
With
GOPACKAGESDRIVER
enabled, adding an import (whether by inline writing code and accepting an import suggestion; or manually adding it to the imports section) will trigger a query to the packages driver. However, this trigger will happen prior to the file being saved, yet the packagesdriver will only get a filename to load packages for.This triggers a bit of a race condition in build systems like Bazel:
file.go
area, b, c
d
$ pkgdrvr file=file.go
)a, b, c
and thus only return info for those 3d
as bad.What did you expect to see?
Since the packagesdriver works with files on disk (in the general case) we should not query the packagesdriver until the IDE has committed the changes on disk.
Alternatively we can extend the packages driver call to query directly for the information of the imported package, rather than indirectly querying for the file the import is added to.
What did you see instead?
Package import resolution fails until language server restart.
I will try to get a project where we can repro this situation in.