x/tools/gopls: adding a file to a package reports failed imports in the other package files #35949
This is consistently reproducible with gopls+VSCode, on many versions of gopls up through
If I add a 5th file, the pre-existing 3 files with import statements in the same package all turn red immediately (in the VSCode file navigator). In those pre-existing 3 files, all of the import statements are now highlighted red with the error "could not import X (no package for import X)".
Adding a blank line to one of the files reporting an import error and re-saving the file does gofmt the file (to remove the blank line), but does not resolve the reported import errors.
Using VSCode's "Go: Restart Language Server" feature immediately updates the VSCode UI to no longer report broken imports.
I noticed that the editor turns red immediately, while the new file is totally empty. I know that for go, an empty
Additionally, after restarting gopls in the workflow above, removing the package declaration from the new file and re-saving does not cause the other files to turn back red. However, as soon as I type
The text was updated successfully, but these errors were encountered:
As suggested above, the problem is that
That leaves the question of why the problem sticks around...
The reason it sticks around is that (*snapshot).shouldCheck doesn't think a reload is needed -- no deps are missing, because there are none, and unless you add an import that gopls hasn't seen yet, it won't ever do a reload. I don't think there's any option but to roll back https://golang.org/cl/201220.
This reverts commit 6f5e273, golang.org/cl/201220. Reason for revert: Produces unusable Package results. See golang/go#35949 and golang/go#35973. Fixes golang/go#35949. Change-Id: Ic4632fe7f00366b1edf59840c83160d66499ba12 Reviewed-on: https://go-review.googlesource.com/c/tools/+/209978 Run-TryBot: Heschi Kreinick <email@example.com> TryBot-Result: Gobot Gobot <firstname.lastname@example.org> Reviewed-by: Rebecca Stambler <email@example.com> (cherry picked from commit 427c522) Reviewed-on: https://go-review.googlesource.com/c/tools/+/210206 Reviewed-by: Heschi Kreinick <firstname.lastname@example.org>