go.nvim
go.nvim copied to clipboard
Prevent LSP errors on codelens
I've noticed that I'm constantly getting an error related to codelens when I go to the definion for the first time.
Error executing vim.schedule lua callback: ...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1146: BufReadPost Autocommands for "*.go": Vim(append):Error executing lua callback: ...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim
/lsp.lua:1963: Vim:method textDocument/codeLens is not supported by any of the servers registered for the current buffer
stack traceback:
[C]: in function 'nvim_command'
...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1963: in function 'buf_request'
...neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/codelens.lua:293: in function 'refresh'
...iktor/.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:67: in function 'refresh'
...iktor/.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:20: in function <...iktor/.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:17>
[C]: in function 'nvim_win_set_buf'
...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1146: in function 'jump_to_location'
...neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/handlers.lua:405: in function 'handler'
...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
[C]: in function 'nvim_win_set_buf'
...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1146: in function 'jump_to_location'
...neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/handlers.lua:405: in function 'handler'
...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
my neovim version:
❯ vim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"
Run :checkhealth for more info
This PR fixes this error by checking if lsp servers are ready when go.nvim is trying to refresh codelenses:
if not vim.lsp.buf.server_ready() then
return
end
I've also changed a bit the behavior of refresh() and clear() to deal only with current buffer and only with codelens provided by gopls.
Additionally, this PR does a bit of cleanups (unify usage of codelens and log withing codelens.lua) and refactors the module a bit to output possible errors more precisely.
Looked through the tests. Failures looks not relevant to my changes. Or am I wrong?
The doc says server_ready is deprecated...
maybe use LspAttach autocmd and add a function to check whether gopls is ready and enable codelens if it is.
Hi, @weirdgiraffe Is it possible we can merge edfadae first and create a separate PR for gopls inlay? I am not quite sure what causing the test failure with the gopls changes. So lets create a dedicated PR for it. Thanks!
Ok. will split
Hello! I created a PR: https://github.com/ray-x/go.nvim/pull/445
It seems like we try to fix the same issue. I tested my solution and it works fine (requiring a lot less code changes)
Maybe I'm wrong and missing something, but it looks like it's enough to find LSP for current buffer without checking it's status.