go: x/tools/cmd/gopls: import organization fails on certain packages
What version of Go are you using (go version)?
$ go version go version go1.11.5 darwin/amd64
Does this issue reproduce with the latest release?
N/A, I think.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/alex/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/alex/.go" GOPROXY="" GORACE="" GOROOT="/usr/local/opt/go/libexec" GOTMPDIR="" GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/alex/Projects/Transparensee/enclosure-core/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qs/wpmg19r12_9_nz7pvvs2_82r0000gn/T/go-build353164800=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
What did you expect to see?
Saved file in VSCode that contains a reference to a struct in a different package, within the same module. I expected the import to be added to import.
What did you see instead?
Nothing was added. This usually works, but there appears to be some packages that just don’t work with import organization. This works fine with Go’s standard library packages as well as third-party packages.
The file is a skeleton main.go, where I added site := models.Site{}. The models package is a package inside the same module.
I don’t know much about gopls and how to report diagnostics, but here’s the log file with RPC logging enabled: gopls.log.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 58 (21 by maintainers)
I’ve now experienced gopls failing many times in the same way, which I think has not yet been reported. I’ll open a file in a package and typically make some change that renders the file uncompilable. Rather than underlining my change with a red squiggle, VS Code underlines the
packagestatement at the top of the file, and hover tells me thatEvery interaction with the file fails, even after I delete the change and return the file to the original state. The gopls log looks like this:
The only fix is quitting VS Code and starting it again.
For the record, my experience with gopls + VSCode on Mac mirrors @atombender; several times a day, I notice that auto-importing and autocompletion have stopped working. Restarting VSCode (and, therefore, gopls) typically solves the issue for awhile. I’d happily run it in some diagnostic mode and report back, if it helps.
edit: I’m on go version go1.12.4 darwin/amd64, in a project using modules, with a go.mod and go.sum, outside of GOPATH.
edit 2: It may also be worth noting the project vendors via
go mod vendor.I can confirm that as well, even in non-go mod repos.