Closed zbindenren closed 2 years ago
Look like you have two ls supporting folding range at the same time.
I am not familiar with the selector for nvim lsp. In coc.nvim, there's a doc selector for each client.
Any tips?
Unfortunately I am not familiar either. Maybe add a help wanted label?
BTW: with the newest version I sometimes still get an exception with neogit:
Error executing vim.schedule lua callback: UnhandledPromiseRejection with the reason:
{ ["message"] = stat /home/rz/repos/gitlab.com/linux/ces/ces-operator/.git/NEOGIT_COMMIT_EDITMSG: no such file or directory, ["code"] = }
What's your clients attach the error buffer? Could you mind post the vim.lsp.get_active_clients({bufnr = bufnr})
result here?
BTW: with the newest version I sometimes still get an exception with neogit:
You must use filetype
to filter out yourself.
Finally, which language sever do you use and always attach any buffer? That's the root cause of the issue you are encountering. I can't reproduce the issue......
And another one for yaml:
Error executing vim.schedule lua callback: UnhandledPromiseRejection with the reason:
{ ["message"] = Request textDocument/foldingRange failed with message: Cannot read property 'lineFoldingOnly' of undefined, ["code"] = -3260 }
can't reproduce all your error, need your language server information.
Update the code.
Run nvim: UFO_LOG=info nvim
Get log: tail -f ~/.cache/nvim/ufo.log
Here the logs:
Maybe the problem could also be the null-ls plugin.
And another one for yaml:
Error executing vim.schedule lua callback: UnhandledPromiseRejection with the reason: { ["message"] = Request textDocument/foldingRange failed with message: Cannot read property 'lineFoldingOnly' of undefined, ["code"] = -3260 }
You haven't set:
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
from the log you provide.
From the log, only one server attach the buffer, I think the this error log is about { ["message"] = Request textDocument/foldingRange failed with message: Cannot read property 'lineFoldingOnly' of undefined, ["code"] = -3260 }
, not the first error you post.
I think I have set it in the configuration (see below):
local status_ok, ufo = pcall(require, "ufo")
if not status_ok then
vim.notify("ufo (fold) plugin not found!")
return
end
vim.wo.foldlevel = 99
vim.wo.foldenable = true
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
local handler = function(virtText, lnum, endLnum, width, truncate)
local newVirtText = {}
local suffix = (" %d "):format(endLnum - lnum)
local sufWidth = vim.fn.strdisplaywidth(suffix)
local targetWidth = width - sufWidth
local curWidth = 0
for _, chunk in ipairs(virtText) do
local chunkText = chunk[1]
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
if targetWidth > curWidth + chunkWidth then
table.insert(newVirtText, chunk)
else
chunkText = truncate(chunkText, targetWidth - curWidth)
local hlGroup = chunk[2]
table.insert(newVirtText, { chunkText, hlGroup })
chunkWidth = vim.fn.strdisplaywidth(chunkText)
-- str width returned from truncate() may less than 2nd argument, need padding
if curWidth + chunkWidth < targetWidth then
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
end
break
end
curWidth = curWidth + chunkWidth
end
table.insert(newVirtText, { suffix, "MoreMsg" })
return newVirtText
end
-- global handler
ufo.setup({
fold_virt_text_handler = handler,
})
I think I have set it in the configuration (see below):
local status_ok, ufo = pcall(require, "ufo") if not status_ok then vim.notify("ufo (fold) plugin not found!") return end vim.wo.foldlevel = 99 vim.wo.foldenable = true local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true, } local handler = function(virtText, lnum, endLnum, width, truncate) local newVirtText = {} local suffix = (" %d "):format(endLnum - lnum) local sufWidth = vim.fn.strdisplaywidth(suffix) local targetWidth = width - sufWidth local curWidth = 0 for _, chunk in ipairs(virtText) do local chunkText = chunk[1] local chunkWidth = vim.fn.strdisplaywidth(chunkText) if targetWidth > curWidth + chunkWidth then table.insert(newVirtText, chunk) else chunkText = truncate(chunkText, targetWidth - curWidth) local hlGroup = chunk[2] table.insert(newVirtText, { chunkText, hlGroup }) chunkWidth = vim.fn.strdisplaywidth(chunkText) -- str width returned from truncate() may less than 2nd argument, need padding if curWidth + chunkWidth < targetWidth then suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth) end break end curWidth = curWidth + chunkWidth end table.insert(newVirtText, { suffix, "MoreMsg" }) return newVirtText end -- global handler ufo.setup({ fold_virt_text_handler = handler, })
If you are using cmp:
local nvim_lsp = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
local servers = {'gopls', 'yamlls'}
for _, ls in ipairs(servers) do
nvim_lsp[ls].setup {
capabilities = capabilities,
on_attach = on_attach,
flags = {debounce_text_changes = 150}
}
end
this seems to work, thx
Neovim version (nvim -v | head -n1)
nvim v0.7.0
Operating system/version
arch linux
How to reproduce the issue
Expected behavior
No exception should happen.
Actual behavior
As mentioned above an exception happens.