LSP not working for Go
Describe the bug
I can't get LSP info from Go code (It works fine for Lua, Rust, Python and TS).
To Reproduce
- Read The Friendly (and well documented)
init.lua - clone this repo
- Have
goplsinstalled within Mason and it is in myecho $PATH - Uncommented
gopls = {}in thelocal serverstable - Created a basic go mod
go mod init ... - Then, when
Kin standard lib function I getNo information availablein the command-line (which works fine for other languages)
Desktop
- OS: MacOS 14.2.1
- Terminal: Alacritty
- gopls version:
golang.org/x/tools/gopls v0.15.1 - go version:
1.22.1
Neovim Version
NVIM v0.9.5
Any help is very appreciated,
Are you in a git repo? Maybe gopls expects a git repo, I'm not sure. Can you show your project structure? it's a bit hard to guess what's going wrong atm
Yes, I created a small test project with a git repo.
This is the structure.
.
├── .git
├── go.mod
├── go.sum
└── main.go
Same for me, looks like a problem with [email protected]. Using version 0.14.2 works fine for me.
I could not get Go 1.22 to work with gopls and nvim also.
btw, if we are using multiple versions of Go on our system, then 1 of the ways to make nvim work with all of them is:
- we need to manually uninstall the current one via
:Mason, - install the gopls for each go versions manually.
For example, if we have go mod file:
gvm applymod
go install golang.org/x/tools/gopls@latest
nvim .
gopls installation is trivial: https://github.com/golang/tools/tree/master/gopls#installation
@tjdevries it's kind of a bummer that a new NeoVim (Kickstart) user will get into this pitfall - 100%. Maybe it should mentioned in the comments, I mean we should install language servers ourselves, no?
Had same issue, it seems it was due to automatic toolchain download introduced in go 1.21 (https://go.dev/doc/toolchain), when gopls was installed inside project directly via downloaded toolchain it didn't work, same issue happened in vscode.
Instead upgraded global installation of go and installed gopls via Mason outside of any go project and it seems to be working
@0xBradock Hi could you please try the work around suggested by @Nvos and close the issue if you're good or let us know if you're not?
Yes, so recently gopls was updated and I did the update through Mason and it is working