Configure nvim-ufo with Neovim LSP
mainWhen using Neovim's built-in LSP, you must manually add the foldingRange capability to your client capabilities, as Neovim does not include it by default. Then, call require('ufo').setup().
-- 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 = vim.lsp.get_clients() -- 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
require('ufo').setup()