Closed pendar747 closed 4 months ago
Reinstalling gopls
as suggested in https://github.com/fatih/vim-go/issues/3584#issuecomment-1743602176 didn't help
Running :GoDef
and gd
work fine for me. I'm happy to troubleshoot this further if you can provide clear reproduction steps and/or a set of Go files (perhaps via a repository?) that can be used to duplicate the behavior you're seeing.
I also see that you provided some of the gopls debug log. Can you start vim with --cmd 'let g:go_debug=["lsp"]'
, duplicate the problem, and provde the full debug log here?
Here's the full log from running with setting --cmd 'let g:go_debug=["lsp"]'
btw GoLSPDebugBrowser
fails with vim-go: gopls was not started with...
even though I have set the lsp
in g:go_debug
===== sent =====
Content-Length: 710
{"method":"initialize","jsonrpc":"2.0","id":1,"params":{"rootUri":"file:///Users/pendar/dev/***","capabilities":{"workspace":{"workspaceFolders":true,"workspaceEdit":{"documentChanges":true},"configuration":true,"didChangeConfiguration":{"dynamicRegistration":true}},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["source.organizeImports","refactor.rewrite","refactor.extract"]}}},"completion":{"completionItem":{"snippetSupport":false}},"hover":{"contentFormat":["plaintext"]}}},"clientInfo":{"name":"vim-go"},"processId":94153,"workspaceFolders":[{"uri":"file:///Users/pendar/dev/***","name":"/Users/pendar/dev/***"}]}}
===== received =====
Content-Length: 259
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/02/28 19:32:09 Handshake session update\n\tupdate_session=3\n\tdebug_address=\"127.0.0.1:56232\"\n\tlogfile=\"\"\n\tserver=\"1\"\n\tgopls_path=\"/Users/pendar/go/bin/gopls\"\n"}}
===== stderr =====
serve.go:441: debug server listening at http://localhost:56232
===== received =====
Content-Length: 4286
{"jsonrpc":"2.0","result":{"capabilities":{"textDocumentSync":{"change":2,"openClose":true,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor.extract","refactor.inline","refactor.rewrite","source.fixAll","source.organizeImports"],"resolveProvider":true},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"renameProvider":true,"foldingRangeProvider":true,"selectionRangeProvider":true,"executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.add_telemetry_counters","gopls.apply_fix","gopls.change_signature","gopls.check_upgrades","gopls.diagnose_files","gopls.edit_go_directive","gopls.fetch_vulncheck_result","gopls.gc_details","gopls.generate","gopls.go_get_package","gopls.list_imports","gopls.list_known_packages","gopls.maybe_prompt_for_telemetry","gopls.mem_stats","gopls.regenerate_cgo","gopls.remove_dependency","gopls.reset_go_mod_diagnostics","gopls.run_go_work_command","gopls.run_govulncheck","gopls.run_tests","gopls.start_debugging","gopls.start_profile","gopls.stop_profile","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.views","gopls.workspace_stats"]},"callHierarchyProvider":true,"semanticTokensProvider":{"full":true,"legend":{"tokenModifiers":[],"tokenTypes":[]},"range":true},"inlayHintProvider":{},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{\"GoVersion\":\"go1.21.2\",\"Path\":\"golang.org/x/tools/gopls\",\"Main\":{\"Path\":\"golang.org/x/tools/gopls\",\"Version\":\"v0.15.1\",\"Sum\":\"h1:WBLlqa3auWKt/jbezarYT204f7IDtCdOn260vY0q4Vk=\",\"Replace\":null},\"Deps\":[{\"Path\":\"github.com/BurntSushi/toml\",\"Version\":\"v1.2.1\",\"Sum\":\"h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=\",\"Replace\":null},{\"Path\":\"github.com/google/go-cmp\",\"Version\":\"v0.6.0\",\"Sum\":\"h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=\",\"Replace\":null},{\"Path\":\"golang.org/x/exp/typeparams\",\"Version\":\"v0.0.0-20221212164502-fae10dda9338\",\"Sum\":\"h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=\",\"Replace\":null},{\"Path\":\"golang.org/x/mod\",\"Version\":\"v0.15.0\",\"Sum\":\"h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=\",\"Replace\":null},{\"Path\":\"golang.org/x/sync\",\"Version\":\"v0.6.0\",\"Sum\":\"h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=\",\"Replace\":null},{\"Path\":\"golang.org/x/telemetry\",\"Version\":\"v0.0.0-20240209200032-7b892fcb8a78\",\"Sum\":\"h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=\",\"Replace\":null},{\"Path\":\"golang.org/x/text\",\"Version\":\"v0.14.0\",\"Sum\":\"h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=\",\"Replace\":null},{\"Path\":\"golang.org/x/tools\",\"Version\":\"v0.18.1-0.20240227180630-1c466157abc9\",\"Sum\":\"h1:DAFzI/OUTyNjVKs2nsM593aR8oHWjVh3ftZ7XQFEKXw=\",\"Replace\":null},{\"Path\":\"golang.org/x/vuln\",\"Version\":\"v1.0.1\",\"Sum\":\"h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=\",\"Replace\":null},{\"Path\":\"honnef.co/go/tools\",\"Version\":\"v0.4.6\",\"Sum\":\"h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=\",\"Replace\":null},{\"Path\":\"mvdan.cc/gofumpt\",\"Version\":\"v0.6.0\",\"Sum\":\"h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=\",\"Replace\":null},{\"Path\":\"mvdan.cc/xurls/v2\",\"Version\":\"v2.5.0\",\"Sum\":\"h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=\",\"Replace\":null}],\"Settings\":[{\"Key\":\"-buildmode\",\"Value\":\"exe\"},{\"Key\":\"-compiler\",\"Value\":\"gc\"},{\"Key\":\"DefaultGODEBUG\",\"Value\":\"panicnil=1\"},{\"Key\":\"CGO_ENABLED\",\"Value\":\"1\"},{\"Key\":\"CGO_CFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CPPFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CXXFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_LDFLAGS\",\"Value\":\"\"},{\"Key\":\"GOARCH\",\"Value\":\"arm64\"},{\"Key\":\"GOOS\",\"Value\":\"darwin\"}],\"Version\":\"v0.15.1\"}"}},"id":1}
===== sent =====
Content-Length: 52
{"method":"initialized","jsonrpc":"2.0","params":{}}
===== sent =====
Content-Length: 210
{"method":"workspace/didChangeWorkspaceFolders","jsonrpc":"2.0","params":{"event":{"added":[{"uri":"file:///Users/pendar/dev/***","name":"/Users/pendar/dev/***"}],"removed":[]}}}
===== sent =====
Content-Length: 212
{"method":"textDocument/didOpen","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///Users/pendar/dev/***","version":3,"languageId":"go","text":"package api\n"}}}
===== received =====
Content-Length: 99
{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":4,"message":"Loading packages..."}}
===== received =====
Content-Length: 158
{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///Users/pendar/dev/***","section":"gopls"}]},"id":1}
===== sent =====
Content-Length: 78
{"id":1,"jsonrpc":"2.0","result":[{"buildFlags":[],"hoverKind":"Structured"}]}
===== received =====
Content-Length: 604
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/02/28 19:32:09 go info for /Users/pendar/dev/***\n(view type GoModView)\n(root dir /Users/pendar/dev/***)\n(go version go version go1.22.0 darwin/arm64)\n(build flags: [])\n(go env: {GOOS:darwin GOARCH:arm64 GOCACHE:/Users/pendar/Library/Caches/go-build GOMODCACHE:/Users/pendar/go/pkg/mod GOPATH:/Users/pendar/go GOPRIVATE:***/* GOFLAGS: GO111MODULE:on GoVersion:21 GoVersionOutput:go version go1.22.0 darwin/arm64\n GOWORK: GOPACKAGESDRIVER:})\n(env overlay: map[])\n\n"}}
===== sent =====
Content-Length: 217
{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package api\n"}],"textDocument":{"uri":"file:///Users/pendar/dev/***","version":4}}}
===== received =====
Content-Length: 268
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/02/28 19:32:10 go/packages.Load #5\n\tsnapshot=0\n\tdirectory=file:///Users/pendar/dev/***\n\tquery=[/Users/pendar/dev/***/... builtin]\n\tpackages=60\n"}}
===== received =====
Content-Length: 156
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/02/28 19:32:10 go/packages.Load #5: updating metadata for 618 packages\n"}}
===== received =====
Content-Length: 106
{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":3,"message":"Finished loading packages."}}
===== received =====
Content-Length: 176
{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"}]},"id":2}
===== sent =====
Content-Length: 38
{"id":2,"jsonrpc":"2.0","result":null}
===== received =====
Content-Length: 99
{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":4,"message":"Loading packages..."}}
===== received =====
Content-Length: 158
{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///Users/pendar/dev/***","section":"gopls"}]},"id":3}
===== sent =====
Content-Length: 78
{"id":3,"jsonrpc":"2.0","result":[{"buildFlags":[],"hoverKind":"Structured"}]}
===== received =====
Content-Length: 182
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/pendar/dev/***","version":4,"diagnostics":[]}}
===== sent =====
Content-Length: 3124
{"method":"textDocument/didOpen","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///Users/pendar/dev/***","version":1,"languageId":"go","text":"package consumer\n\nimport (\n\t\"context\"\n\n\t\"***"}}}
===== received =====
Content-Length: 196
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/pendar/dev/***","version":1,"diagnostics":[]}}
===== sent =====
Content-Length: 3129
{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package consumer\n\nimport (\n\t\"context\"\n\n\t\"***\"\n\t\"***/***","version":2}}}
===== received =====
Content-Length: 196
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/pendar/dev/***","version":2,"diagnostics":[]}}
===== sent =====
Content-Length: 221
{"method":"textDocument/definition","jsonrpc":"2.0","id":2,"params":{"textDocument":{"uri":"file:///Users/pendar/dev/***"},"position":{"character":60,"line":26}}}
===== received =====
Content-Length: 38
{"jsonrpc":"2.0","result":null,"id":2}
I don't see any particular problems in the logs. To proceed, I'm going to need to know how to replicate this. If you can construct a simple script or set of files that can be used to demonstrate the problem, I would greatly appreciate it.
So this is the minimum example that reproduces the problem:
// main.go
package main
func my_func() {
print("my_func")
}
func main() {
print("hello world")
my_func()
}
module my-go-module
go 1.22
toolchain go1.22.0
setting the go version in go.mod
to 1.21
fixes the issue, but breaks on 1.22
Unfortunately, I can't replicate this. I created a new directory and then placed the contents of the two code blocks you provided into files named main.go
and go.mod
, respectively, in that new directory. I can jump from the my_func()
call to the function definition consistently and without any problem.
Looks like this issue gets resolved by running go install ./cmd/services/...
to install some supporting tools we have there. I don't understand why this was causing an issue though.
In case this helps anyone the fix I mentioned in the above message didn't actually work. The real fix was to reinstall go to the latest version (v1.22.0) that was referenced in the project and reinstall gopls by removing it and running go install golang.org/x/tools/gopls@latest
I had v1.21.00 installed but v1.22.00 was available via go toolchain so when checking go version
in the project directory I would see v1.22.00
however running gopls -vv version
showed that it was built for v1.21.00
despite having v1.22.00
so the solution was to reinstall/update go to v1.22.00
Ran into the exact same thing today. Thank you for sharing you fix @pendar747.
What did you do? (required: The issue will be closed when not provided)
Running
:GoDef
to follow references.What did you expect to happen?
What happened instead?
vim-go does not follow the definition and gopls returns null results when following definitions without any errors.
This is the response from gopls by setting
let g:go_gopls_enabled=1
:Configuration (MUST fill this out):
This seems to have become an issue since we added
toolchain
in our go.mod:vim-go version:
vimrc
you used to reproduce:vimrc
```vim ```Vim version (first three lines from
:version
):VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Dec 20 2023 18:58:31) macOS version - arm64 Included patches: 1-2136
Go version (
go version
):go version go1.22.0 darwin/arm64
Go environment
go env
Output:gopls version
gopls version
Output:vim-go configuration:
vim-go configuration
filetype detection configuration:
filetype detection