fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
15.97k stars 1.45k forks source link

GoDef doesn't work with `go 1.23` in go.mod #3688

Closed slingamn closed 1 hour ago

slingamn commented 3 hours ago

What did you do? (required: The issue will be closed when not provided)

  1. Edit files in a project where go.mod specifies go 1.23 as the required Go version
  2. Trigger jump-to-definition with :GoDef or gd

What did you expect to happen?

vim-go jumps to definition, as it does with go 1.22 in go.mod

What happened instead?

The status bar prints vim-go: [definition] SUCCESS but there is no jump to definition; cursor remains over the current token

Configuration (MUST fill this out):

vim-go version:

v1.28

vimrc you used to reproduce:

vimrc ```vim set encoding=utf-8 syntax on filetype plugin indent on ```

Vim version (first three lines from :version):

vim on Ubuntu 22.04, package version 2:8.2.3995-1ubuntu2.18:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug 27 2024 05:34:22)
Included patches: 1-16, 647, 17-579, 1969, 580-647, 678, 648-1848, 4975, 5016, 5023, 5072, 2068, 1849-1854, 1857, 1855-1857, 1331, 1858, 1858-1859, 1873, 1860-1969, 1992, 1970-1992, 2010, 1993-2068, 2106, 2069-2106, 2108, 2107-2109, 2109-3995, 4563, 4646, 4774, 4895, 4899, 4901, 4919, 213, 1840, 1846-1847, 2110-2112, 2121
Modified by team+vim@tracker.debian.org

Go version (go version):

go version go1.23.1 linux/amd64

Go environment

go env Output:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/shivaram/.cache/go-build'
GOENV='/home/shivaram/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/shivaram/go/pkg/mod'
GONOPROXY='[REDACTED]'
GONOSUMDB='[REDACTED]'
GOOS='linux'
GOPATH='/home/shivaram/go'
GOPRIVATE='[REDACTED]'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/shivaram/.config/go/telemetry'
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-build1382972574=/tmp/go-build -gno-record-gcc-switches'

gopls version

gopls version Output:

golang.org/x/tools/gopls v0.15.2

bhcleek commented 3 hours ago

There must be more to it than that. I can use godef to jump to definition in a simple package when the go.mod has go 1.23 without a problem.

Have you tried updating godef (e.g. :GoUpdateBinaries godef)?

Can you execute :let g:go_debug=['shell-command'] in your vim session and then try jumping to the definition using :GoDef or gd? After that, I'd like to know the output of :messages. If you're feeling up to it or if the output of :messages doesn't seem to reveal anything, then you could execute whatever godef command is revealed by :messages and execute it on the command line to see what godef reports directly.

slingamn commented 2 hours ago

Thanks for your time! I tried updating godef but it didn't seem to help. (go version -m says it's godef v1.1.2 now.)

I tried issuing :let g:go_debug=['shell-commands'] but I don't see anything informative in :messages, it looks like:

vim-go: initializing gopls
vim-go: initialized gopls
vim-go: Finished loading packages.
vim-go: [definition] SUCCESS
vim-go: [definition] SUCCESS
slingamn commented 2 hours ago

I may be entering the debug command incorrectly because when I downgrade go.mod to 1.22, jump-to-definition works again, but I still don't see anything useful in :messages:

"irc/server.go" 1162L, 41949B
vim-go: initializing gopls
vim-go: initialized gopls
vim-go: Finished loading packages.
vim-go: [definition] SUCCESS
"irc/modes/modes.go" 474L, 11633B
"irc/server.go" 1162L, 41949B
vim-go: [definition] SUCCESS
"irc/caps/defs.go" 191L, 6387B
bhcleek commented 2 hours ago

It would help if I could spell correctly. That should be shell-commands instead of shell-command. I corrected my previous message, too, FWIW. Sorry about that.

slingamn commented 2 hours ago

Hmm, with go.mod set to go 1.22, when I issue the debug command :let g:go_debug=['shell-commands'] and then use :GoDef I see something, but it doesn't seem pertinent:

vim-go: initializing gopls
vim-go: initialized gopls
vim-go: Finished loading packages.
vim-go: [definition] SUCCESS
"irc/connection_limits/tor.go" 49L, 1093B
vim-go: [definition] SUCCESS
"irc/connection_limits/throttler.go" 51L, 1413B
vim-go: shell command: '/usr/local/go/bin/go' 'env' 'GOMOD'
vim-go: [definition] SUCCESS
"irc/connection_limits/tor.go" 49L, 1093B
"irc/server.go" 1162L, 41949B
vim-go: [definition] SUCCESS
"irc/whowas.go" 93L, 2073B
vim-go: shell command: '/usr/local/go/bin/go' 'env' 'GOMOD'

With go.mod set to go 1.23 I see the same output as before.

bhcleek commented 1 hour ago

I'm so sorry. I misread your issue and thought it was specifically related to godef, but it's not. It looks like you're using gopls for jumping to definitions. In that case, make sure you do :GoUpdateBinaries gopls and try again. If there's no improvement, then we need to use :let g:go_debug=['lsp'], try again, and I'll need to see the contents of the __GOLSP_LOG__ window.

slingamn commented 1 hour ago

Thanks very much! I updated to golang.org/x/tools/gopls v0.16.2 and that fixed it.