Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: missing packages when using GOPACKAGESDRIVER are vaguely attributed to GOROOT/GOPATH #64980

Open
JamyDev opened this issue Jan 5, 2024 · 1 comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@JamyDev
Copy link

JamyDev commented Jan 5, 2024

gopls version

0.14.1

go env

GO111MODULE='off'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT='nocoverageredesign'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/go-code/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go-code'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/.cache/pkgdrv/0ddf1c72b811bee41d29991c732306ef72553747/external/go_sdk'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/user/.cache/pkgdrv/0ddf1c72b811bee41d29991c732306ef72553747/external/go_sdk/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5 X:nocoverageredesign'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD=''
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build797902082=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Sometimes for various reasons a package may fail to resolve in the packagesdriver. When this happens, gopls warns about a BrokenImport.

What did you see happen?

The error indicates that it's not found in GOROOT/GOPATH even though it's likely something else went wrong while looking up the packages.

image

could not import github.com/bazelbuild/buildtools/build_proto (cannot find package "github.com/bazelbuild/buildtools/build_proto" in GOROOT or GOPATH) compiler BrokenImport

What did you expect to see?

could not import github.com/bazelbuild/buildtools/build_proto (package not provided by external packages driver in ./tools/gopackagesdriver.sh) compiler BrokenImport

Editor and settings

https://github.com/bazelbuild/rules_go/wiki/Editor-setup

Logs

No response

@JamyDev JamyDev added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Jan 5, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 5, 2024
@findleyr
Copy link
Contributor

findleyr commented Jan 6, 2024

Thanks. Yes we can and should do better here.

The problem is here: https://cs.opensource.google/go/x/tools/+/master:gopls/internal/lsp/cache/check.go;l=1751;drc=782573673af31588817cb7e79a1baeca1570609c

Indirectly, the problem is that we serialize and cache diagnostics resulting from type checking, independent of where package information came from (though we do have the 'moduleMode' bit hashed into our cache key).

The simplest thing to do would be to hash GOPACKAGESDRIVER into the cache key, and use it in the error message. Though per this comment, perhaps we should do something more sophisticated. It's a pain to have to thread these type of superficial improvements through our cache key.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.16.0 Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants