Closed windowsrefund closed 1 year ago
-- Option 2: nvim lsp as LSP client
-- Tell the server the capability of foldingRange,
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
That does not work. Have you opened a yaml file yourself with that setup (with yamlls installed and attached to the buffer)?
Work for me. Debug yourself to make sure capabilities.textDocument
contains foldingRange
.
Acttually, I had exactly same error with exactly same yaml langserver.
Problem was exactly in the fact that I missed to pass capabilities
to exactly that langserver.
FYI, @windowsrefund
I have added this lines of code to include the capabilities in the available language servers (this file is in my .config/lvim/after/plugin/nvim-ufo.lua
)
vim.o.foldcolumn = '1' -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
-- Tell the server the capability of foldingRange,
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
local language_servers = require("lspconfig").util.available_servers() -- or list servers manually like {'gopls', 'clangd'}
for _, ls in ipairs(language_servers) do
require('lspconfig')[ls].setup({
capabilities = capabilities
-- you can add other fields for setting up lsp server in this table
})
end
local builtin = require("statuscol.builtin")
require("statuscol").setup({
relculright = true,
segments = {
{ text = { builtin.foldfunc }, click = "v:lua.ScFa" },
{ text = { "%s" }, click = "v:lua.ScSa" },
{ text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
},
})
require('ufo').setup()
But for some reason I keep getting this "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" error message every time I open a yaml file.
When I do check if the ymlls server is available, it in fact is!
How can I check if the capability has been added to my ls on runtime (i.e. after lunarvim has gone through the whole configuration setup) ?
If you added the capabilities but still experience the issue, most like you have another plugin that overwrites your lsp config like yaml-chamption
https://github.com/someone-stole-my-name/yaml-companion.nvim/blob/4de1e1546abc461f62dee02fcac6a02debd6eb9e/lua/yaml-companion/config.lua#L15.
Issue here https://github.com/someone-stole-my-name/yaml-companion.nvim/issues/37.
For yaml-companion
one of the fixes is to additionally pass it again into the plugin
like
{
"someone-stole-my-name/yaml-companion.nvim",
ft = { "yaml" },
dependencies = {
{ "neovim/nvim-lspconfig" },
{ "nvim-lua/plenary.nvim" },
{ "nvim-telescope/telescope.nvim" },
},
opts = {
lspconfig = {
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
},
},
},
},
}
Neovim version (nvim -v | head -n1)
0.7.2
Operating system/version
Who cares
How to reproduce the issue
Open any YAML file
Expected behavior
Expect folds to work
Actual behavior
Tried every configuration example I can find on this site including #21 but nothing works.