Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telescope lsp_definitions clashing with go.nvim first time it's called #434

Open
asirago opened this issue Mar 4, 2024 · 20 comments
Open

Comments

@asirago
Copy link

asirago commented Mar 4, 2024

It works as expected when go.nvim is not installed or loaded (lazy.vim) however hen go.nvim is installed and loaded the first telescope lsp_definitions outside buffer yields the error under Actual Behaviour.

Since the error complained about codelens I tried setting lsp_codelens to false and got this error instead
method textDocument/inlayHint is not supported by any of the servers registered for the current buffer

I'm relatively new to the world of neovim and custom configurations so something might be wrong with my configurations, however I thought it would still be worthwhile creating a new issue since there's a chance that might not be the case.

Expected behaviour

no error

Actual Behaviour

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):E
rror 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'
        .../.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:67: in function 'refresh'
        .../.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:20: in function <.../.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'
        ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:176: 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'
        ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:176: 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>

This is my lsp_config.lua if it's relevant

return {
    "neovim/nvim-lspconfig",
    dependencies = {
        "hrsh7th/cmp-nvim-lsp",
        { "antosha417/nvim-lsp-file-operations", config = true }
    },
    config = function()
        local lspconfig = require("lspconfig")
        vim.api.nvim_create_autocmd('LspAttach', {
            callback = function(event)
                local map = function(mode, lhs, rhs, desc)
                    vim.keymap.set(mode, lhs, rhs, { buffer = event.buf,  desc = desc .. "[lsp]" })
                end

                map("n", "gd", "<cmd>Telescope lsp_definitions<CR>", "[g]o [t]o definition") -- see definition and make edits in window

                local client = vim.lsp.get_client_by_id(event.data.client_id)
                if client and client.server_capabilities.documentHighlightProvider then
                    vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
                        buffer = event.buf,
                        callback = vim.lsp.buf.document_highlight,
                    })

                    vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
                        buffer = event.buf,
                        callback = vim.lsp.buf.clear_references,
                    })
                end
            end,
        })

        local capabilities = vim.lsp.protocol.make_client_capabilities()
        capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())

        -- configure go server
        lspconfig["gopls"].setup({
            capabilities = capabilities,
            filetypes = { "go", "gomod", "gowork", "gotmpl" },
        })

        -- configure lua server (with special settings)
        lspconfig["lua_ls"].setup({
            capabilities = capabilities,
            settings = { -- custom settings for lua
                Lua = {
                    -- make the language server recognize "vim" global
                    diagnostics = {
                        globals = { "vim", "hs" },
                    },
                    workspace = {
                        -- make language server aware of runtime files
                        library = {
                            [vim.fn.expand("$VIMRUNTIME/lua")] = true,
                            [vim.fn.stdpath("config") .. "/lua"] = true,
                        },
                    },
                },
            },
        })
}
@icefed
Copy link
Contributor

icefed commented Mar 4, 2024

Error executing vim.schedule lua callback: .../.config/nvim/plugged/glance.nvim/lua/glance/preview.lua:59: 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 textDoc
ument/codeLens is not supported by any of the servers registered for the current buffer

Same error on github.com/DNLHC/glance.nvim.

@jens1205
Copy link

jens1205 commented Mar 4, 2024

Same error here, quite annoying. Happens for each external dependency once, when I do a lua require('telescope.builtin').lsp_definitions()

Error executing vim.schedule lua callback: ...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1146: BufReadPost Autokommandos für "*.go": Vim(append):Error executing lua callback: ...l/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'                                                                                                                                                                              
        ...l/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'                                                                                                                       
        ...re/nvim/site/pack/packer/opt/go.nvim/lua/go/codelens.lua:67: in function 'refresh'                                                                                                                        
        ...re/nvim/site/pack/packer/opt/go.nvim/lua/go/codelens.lua:20: in function <...re/nvim/site/pack/packer/opt/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'                                                                                                             
        ...ker/start/telescope.nvim/lua/telescope/builtin/__lsp.lua:168: in function 'handler'                                                                                                                       
        ...l/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'                                                                                                             
        ...ker/start/telescope.nvim/lua/telescope/builtin/__lsp.lua:168: in function 'handler'                                                                                                                       
        ...l/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''                                                                                                                             
        vim/_editor.lua: in function <vim/_editor.lua:0>                

@icefed
Copy link
Contributor

icefed commented Mar 8, 2024

@asirago @jens1205

go.nvim default configuration conflict with other lsp plugins, you can disable those options:

  require("go").setup({
    lsp_codelens = false,
    lsp_keymaps = false,
    lsp_inlay_hints = {
      enable = false,
    },
  })

@jens1205
Copy link

@icefed Thanks, that seems to do the trick!

@ray-x
Copy link
Owner

ray-x commented Mar 12, 2024

I suggest using the LSP setup from go.nvim. As it turned on features that may not enabled by other LSP setup/plugins.

@i-vrnv
Copy link

i-vrnv commented Mar 22, 2024

Hi!
I have the same issue

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: ...l/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'
        ...l/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'
        .../user/.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:67: in function 'refresh'
        .../user/.local/share/nvim/lazy/go.nvim/lua/go/codelens.lua:20: in function <.../user/.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'
        ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:175: in function 'handler'
        ...l/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'
        ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:175: in function 'handler'
        ...l/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

and @icefed method works(Thank you!)

  require("go").setup({
    lsp_codelens = false,
  })

I'm using lsp-zero. How to use go.nvim and lsp-zero at the same time? @ray-x

@ray-x
Copy link
Owner

ray-x commented Mar 23, 2024

I am not familar with lsp-zero
You can get gopls dynamicity with

     require('go.lsp').config()

And passing it to lsp-zero config
Something like

require('lspconfig').gopls.setup(require('go.lsp').config())

@IlyasYOY
Copy link

IlyasYOY commented Mar 25, 2024

Hello! I faced the same issue.

I found that codelense causes error here:

function M.refresh()

Every time we open a new dependency, we open a new gopls instance.

 Client: gopls (id: 4, bufnr: [129])
 	filetypes:       go, gomod, gosum, gotmpl, gohtmltmpl, gotexttmpl
 	autostart:       true
 	root directory:  Running in single file mode.
 	cmd:             /Users/iilinykh/.local/share/nvim/mason/bin/gopls -remote=auto

seems like we have this call failing because we use wrong gopls.

@IlyasYOY
Copy link

In my case problem was solved by this fix: #445

@i-vrnv
Copy link

i-vrnv commented Mar 25, 2024

After plugin update the problem is gone. @ray-x thanks for your efforts!

@IlyasYOY FYI. I assume this commit have fixed the issue.

@IlyasYOY
Copy link

I guess you are right @i-vrnv. I've just checked one more time and everything looks fine.

closed the PR. @ray-x +1, you did a great job, thanks for the plugin!

@gcollura
Copy link

@i-vrnv How did you actually fix the issue? For me it still shows that error (but codeLens initially works, without errors), but then after using glance.nvim, ctrl-q to move the results to quickfix, and then browsing the result from quickfix, things start to break. It's interesting that GoCodeLensAct still works, despite saying that method textDocument/codeLens is not supported by any of the servers registered for the current buffer and it runs test or whatever action is on that line. Here's my config https://github.com/gcollura/dotfiles/tree/main/.config/nvim

@i-vrnv
Copy link

i-vrnv commented Apr 30, 2024

Hi @gcollura! I didn't make any adjustments. I just updated the packages via Lazy. I don't use glance.nvim. It might be worth trying to disable it and see if the behavior changes. Here is my config, maybe it will help.

@ray-x
Copy link
Owner

ray-x commented May 1, 2024

I do not think default gopls setup from other plugins will enable all required gopls features of go.nvim.
you can either require('lspconfig').gopls.setup(require('go.lsp').config()) or check what are the differences between go.nvim gopls config and the setup in other plugins and update the gopls setup accordingly.

@gcollura
Copy link

gcollura commented May 1, 2024

I do not think default gopls setup from other plugins will enable all required gopls features of go.nvim. you can either require('lspconfig').gopls.setup(require('go.lsp').config()) or check what are the differences between go.nvim gopls config and the setup in other plugins and update the gopls setup accordingly.

Right, I'm doing that, and everything actually works fine, but doing :copen, even without going through Glance, seems to throwing things off:

Error detected while processing BufReadPost Autocommands for "*.go":
method textDocument/codeLens is not supported by any of the servers registered for the current buffer

I wonder if maybe there's an issue (in my config probably) in reattaching the LSP after opening a buffer without any LSP attached to it?

@luv2code
Copy link
Contributor

luv2code commented May 6, 2024

I have the same issue as gcollura. I launch neovim, run :GoLint and the quickfix appears. The first time I hit enter on an item in quickfix, I get this codeLens not supported error. It comes up the first time a buffer is loaded from quickfix. Selecting further lines in quickfix on the same buffer doesn't trigger the codeLens error.

Here's my config:
https://github.com/luv2code/nvim/blob/e7c79617a9f93b8949ebc84d9cbee3bc0aa0b595/after/plugin/lsp.lua

require('mason-lspconfig').setup({
	ensure_installed = {
		'tsserver',
		'eslint',
		'rust_analyzer',
		'gopls',
		'tailwindcss',
		'html',
		'htmx',
		'clangd',
		'cssls',
		'templ',
	},
	handlers = {
		function(server_name)
			require('lspconfig')[server_name].setup({})
		end,
		gopls = function ()
			require('lspconfig').gopls.setup(require('go.lsp').config())
		end,
		tailwindcss = function ()
			require('lspconfig').tailwindcss.setup({
					filetypes = { "templ", "javascript", "typescript", "react" },
					init_options = { userLanguages = { templ = "html" } },
			})
		end,
	},
})

edit:
Once this codelens error is triggered from quickfix. I start getting it on other events too. Like if I exit insert mode into normal mode, it pops up on InsertLeave instead of BufReadPost. Or if I write the file, it pops up with BufWritePre.

Also, it doesn't matter from where the quickfix was launched. I can grep into a quickfix buffer and the same error starts popping up.

The behavior persists even after the quickfix window is closed. The codelens error persists until neovim is restarted.

@ray-x
Copy link
Owner

ray-x commented May 9, 2024

When opened file in quickfix, did gopls attach to the file just opened? You can check it with LspInfo

@luv2code
Copy link
Contributor

 Press q or <Esc> to close this window. Press <Tab> to view server doc.
 
 Language client log: /home/matt/.local/state/nvim/lsp.log
 Detected filetype:   go
 
 2 client(s) attached to this buffer: 
 
 Client: copilot (id: 1, bufnr: [1, 30, 43, 51, 29])
 	filetypes:       
 	autostart:       false
 	root directory:  /home/matt/projects/[redacted]
 	cmd:             node /home/matt/.local/share/nvim/site/pack/packer/start/copilot.lua/copilot/index.js
 
 Client: gopls (id: 2, bufnr: [43, 30, 29])
 	filetypes:       go, gomod, gosum, gotmpl, gohtmltmpl, gotexttmpl
 	autostart:       true
 	root directory:  /home/matt/projects/[redacted]
 	cmd:             /home/matt/.local/share/nvim/mason/bin/gopls -remote=auto
 
 Configured servers list: tailwindcss, html, gopls, clangd, lua_ls, htmx, templ, cssls, eslint, rust_analyzer, tsserver

It looks like it attached; though I know how to run LspInfo until after I dismiss the errors.

@ray-x
Copy link
Owner

ray-x commented May 13, 2024

If check the bufnr gopls and copilot attached. seems 1 and 51 were not attached. Not sure those are go files though.

@luv2code
Copy link
Contributor

luv2code commented May 13, 2024

1 was the makefile, and 51 was the quickfix buffer.

Here it is again. I opened neovim fresh, and ran :grep "func main\(" which loads a quickfix list without opening a qf buffer, and then opens the first result in the list into a new buffer.

 Press q or <Esc> to close this window. Press <Tab> to view server doc.
 
 Language client log: /home/matt/.local/state/nvim/lsp.log
 Detected filetype:   go
 
 2 client(s) attached to this buffer: 
 
 Client: copilot (id: 1, bufnr: [1])
 	filetypes:       
 	autostart:       false
 	root directory:  /home/matt/projects/[redacted]
 	cmd:             node /home/matt/.local/share/nvim/site/pack/packer/start/copilot.lua/copilot/index.js
 
 Client: gopls (id: 2, bufnr: [1])
 	filetypes:       go, gomod, gosum, gotmpl, gohtmltmpl, gotexttmpl
 	autostart:       true
 	root directory:  /home/matt/projects/[redacted]
 	cmd:             /home/matt/.local/share/nvim/mason/bin/gopls -remote=auto
 
 Configured servers list: tailwindcss, html, markdown_oxide, clangd, lua_ls, htmx, templ, tflint, eslint, cssls, tsserver, rust_analyzer, gopls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants