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:
Current imports in file.go are a, b, c
I add import d
GoPLS immediately tries to look up package info from the driver using the filename ($ pkgdrvr file=file.go)
Since the file isn't saved at this point in time, the packagesdriver will only see imports a, b, c and thus only return info for those 3
GoPLS gets incomplete results back and flags import d as bad.
Even after save, there is no re-trigger of the packagesdriver, which means this bad imports stays bad until after the imports are changed again; or the language server is restarted.
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.
The text was updated successfully, but these errors were encountered:
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
Apr 13, 2023
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:
accumulate invalidations in cache.snapshot.clone while the user types.
only invalidate and reload packages when the user saves all files
...but this will be very tricky to implement, and even after implemented may have to a subtly confusing UX.
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.
The text was updated successfully, but these errors were encountered: