Gopls has some support for ad-hoc packages, which are packages defined in a directory outside of a module or GOPATH. To support them, it sets GO111MODULE=auto and loads .. However, I observe that gopls also load individual files eagerly, and this can lead to conflicting state.
Consider the following simple ad-hoc package:
--- a.go ---
package foo
const X = 1
--- b.go ---
package foo
const Y = X
If I trigger repeated reloads of b.go (for example, by typing in an import statement in b.go), I can sometimes trigger a state where I can an "undefined name: X" diagnostics even though cross references on X work. The reason for this, I assume, is that we eagerly load file:b.go before reloading the directory ., resulting in multiple packages containing b.go, one of which does not contain a.go.
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
Dec 9, 2022
Gopls has some support for ad-hoc packages, which are packages defined in a directory outside of a module or GOPATH. To support them, it sets
GO111MODULE=auto
and loads.
. However, I observe that gopls also load individual files eagerly, and this can lead to conflicting state.Consider the following simple ad-hoc package:
If I trigger repeated reloads of
b.go
(for example, by typing in an import statement in b.go), I can sometimes trigger a state where I can an "undefined name: X" diagnostics even though cross references on X work. The reason for this, I assume, is that we eagerly loadfile:b.go
before reloading the directory.
, resulting in multiple packages containingb.go
, one of which does not containa.go
.CC @adonovan
The text was updated successfully, but these errors were encountered: