kickstart.nvim icon indicating copy to clipboard operation
kickstart.nvim copied to clipboard

LSP not working for Go

Open 0xBradock opened this issue 1 year ago • 7 comments

Describe the bug

I can't get LSP info from Go code (It works fine for Lua, Rust, Python and TS).

To Reproduce

  1. Read The Friendly (and well documented) init.lua
  2. clone this repo
  3. Have gopls installed within Mason and it is in my echo $PATH
  4. Uncommented gopls = {} in the local servers table
  5. Created a basic go mod go mod init ...
  6. Then, when K in standard lib function I get No information available in 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,

0xBradock avatar Mar 11 '24 18:03 0xBradock

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

tjdevries avatar Mar 15 '24 14:03 tjdevries

Yes, I created a small test project with a git repo.

This is the structure.

 .
├──  .git
├──  go.mod
├──  go.sum
└──  main.go

0xBradock avatar Mar 15 '24 17:03 0xBradock

Same for me, looks like a problem with [email protected]. Using version 0.14.2 works fine for me.

danielcondemarin avatar Mar 17 '24 20:03 danielcondemarin

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:

  1. we need to manually uninstall the current one via :Mason,
  2. 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?

gauffer avatar Mar 19 '24 17:03 gauffer

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

Nvos avatar Mar 23 '24 23:03 Nvos

@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?

feoh avatar Mar 27 '24 14:03 feoh

Yes, so recently gopls was updated and I did the update through Mason and it is working

0xBradock avatar Mar 28 '24 09:03 0xBradock