golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.79k stars 17.64k forks source link

x/tools/gopls: symbol definitions not found after latest vscode/gopls upgrade #66677

Closed eliben closed 6 months ago

eliben commented 6 months ago

What did you do?

Clone a github repo, e.g. https://github.com/eliben/gemini-cli

$ cd gemini-cli $ code .

Navigate to main.go and click "Go to definition" on the Execute symbol on line 10

What did you expect to see?

Expected to jump to definition.

What did you see instead?

"No definition found for Execute" popup

Build info

golang.org/x/tools/gopls v0.15.2
    golang.org/x/tools/gopls@v0.15.2 h1:4JKt4inO8JaFW3l/Fh9X1k/5JQn+iUOpdc4/Lpi0mOs=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
    golang.org/x/sync@v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
    golang.org/x/telemetry@v0.0.0-20240209200032-7b892fcb8a78 h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=
    golang.org/x/text@v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
    golang.org/x/tools@v0.18.1-0.20240311201521-78fbdeb61842 h1:No0LMXYFkp3j4oEsPdtY8LUQz33gu79Rm9DE+izMeGQ=
    golang.org/x/vuln@v1.0.1 h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
    honnef.co/go/tools@v0.4.6 h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
    mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.21.1

This happened today, after an auto-upgrade of vscode.

$ code --version
1.87.2
863d2581ecda6849923a2118d93a088b0745d9d6
x64

I don't see errors in the gopls (server) in the Output terminal. Extension Host terminal says:

2024-04-04 06:36:26.948 [info] ExtensionService#_doActivateExtension golang.go, startup: false, activationEvent: 'onLanguage:go'
findleyr commented 6 months ago

Hi Eli, thanks for filing.

I can reproduce this by installing gopls with go 1.21, and it is fixed by installing gopls with go 1.22. I believe VS Code should have prompted to reinstall tools upon the version mismatch, but it didn't, for me (CC @hyangah).

I'm haven't yet investigated the failure mode, which is rather disconcerting: no errors, just a broken experience.

findleyr commented 6 months ago

This is a manifestation of #66525: (1) go/types fails fast with an error when the language version is newer than its runtime version, and (2) this error is not reported through the error handler, therefore not seen by gopls. Hence the silent brokenness of your workspace: go list happily lists packages and gopls happily type checks them, but they are empty.

We need to guard against this when built with 1.21.x, since this is a very bad failure mode. We should capture a synthetic type checking diagnostic, and unset types.Config.GoVersion to proceed with type checking.

eliben commented 6 months ago

Thanks for the quick response, @findleyr

Indeed, removing gopls and re-installing it with 1.22 solved the issue for me.

hyangah commented 6 months ago

@findleyr About the prompt for tools update not showing up - do you happen to have 'go.toolsManagement.autoUpdate' set? I just tested it with the default setting ("go.toolsManagement.autoUpdate": false) and got the following prompt. Screenshot 2024-04-04 at 4 13 52 PM

If the setting is 'true', the extension tries to rebuild and restart gopls without prompt, but, sadly, due to the issue like https://github.com/golang/vscode-go/issues/3168, go install runs with the system version of go (in this case 1.21.x). :-(

findleyr commented 6 months ago

@hyangah -- I'm sorry: I just tried again and got the popup (but it went away after ~10s). I must have missed it.

gopherbot commented 6 months ago

Change https://go.dev/cl/576678 mentions this issue: internal/check: filter out too-new Go versions for type checking

gopherbot commented 6 months ago

Change https://go.dev/cl/577302 mentions this issue: [gopls-release-branch.0.15] internal/check: filter out too-new Go versions for type checking