-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: importing wrong package "golang.org/x/exp/slices" #63641
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
Comments
what's in your go.mod? |
❯ cat ../../go/example/go.mod go 1.21.3 |
@jgardona did you end up with exp/slices as part of a completion or as part of "organize imports" (possibly on save)? In other words, was it from doing something like:
or:
|
@danp Hello. Good afternoon. Exactly. I typed "slices.", then hit enter and "golang.org/x/exp/slices" was imported. |
I see you're using I believe the issue is that gopls embeds a list of stdlib packages and their exported symbols. That list is used by the completion bits to understand what stdlib packages are available. You can see the version of that list gopls v0.13.2 uses here (which, because gopls is its own module and requires tools, is dependent on what go.mod says here). There's no entry for the stdlib slices package since list was generated using info from Go 1.20 (as mentioned in the commit message). To get a version of gopls that uses the more recent list generated from Go 1.21 (which does include slices) you'd need to try a gopls v0.14.0 prerelease, such as gopls/v0.14.0-pre.4. You should be able to try it with the example And hopefully someone from the gopls team will correct me if I've gotten something wrong! |
I'll wait gopls 0.14.0 and see what will be the output. |
gopls v0.14.0 is out now. @jgardona please let us know if this resolves your problem. |
confirmed here it was fixed. Thank you all 🙂 |
will close as it was fixed in 0.14 |
I don't know exactly if this is an issue of gopls, but I think its good to post it here.
When using slices package, the lsp will always import the wrong go package
"golang.org/x/exp/slices", instead of the correct package "slices".
gopls version
go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/jgardona/snap/alacritty/common/.cache/go-build'
GOENV='/home/jgardona/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jgardona/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jgardona/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/jgardona/Bin/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/jgardona/Bin/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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-build251818100=/tmp/go-build -gno-record-gcc-switches'
What did you do?
Use slices package and wait for the gopls autocomplete works
What did you expect to see?
Import "slices" package
What did you see instead?
It imports "golang.org/x/exp/slices" package
Editor and settings
vscode info
Version: 1.83.1
Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
Date: 2023-10-10T23:45:31.402Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Linux x64 6.5.0-9-generic snap
no settings
The text was updated successfully, but these errors were encountered: