yaml-language-server
yaml-language-server copied to clipboard
`[SOLVED]` RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')"
Describe the bug
When using yaml-language-server from mason, writing a .yaml buffer causes the error:
Error executing vim.schedule lua callback: UnhandledPromiseRejection with the reason:
RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')"
Expected Behavior
No errors on write
Current Behavior
Error on write
Steps to Reproduce
- Install yaml-language-server using mason.
- Open a yaml file
- Write it into disk
Environment
- [ x ] Arch Linux
This is one is gonna be tough to debug because it doesn't reproduce consistently, give me more time to debug.
It's not bug of yaml-language-server. Maybe you use https://github.com/kevinhwang91/nvim-ufo or plugin that use dynamicRegistration of LSP.
You can see configuration of LSP capabilities in https://github.com/kevinhwang91/nvim-ufo/tree/main#minimal-configuration (option 2), or in my config https://github.com/dynamotn/neovim-config/commit/e7fa4caa45da0cef37ce4d997ac05c64935e843f
I can confirm what @dynamotn said andthat's works for me:
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
For those using Mason:
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
require("mason-lspconfig").setup_handlers {
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {
capabilities = capabilities,
}
end,
["yamlls"] = function()
require("lspconfig").yamlls.setup {
capabilities = capabilities,
settings = {
yaml = {
schemas = {
kubernetes = "/*.yaml",
-- Add the schema for gitlab piplines
-- ["https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"] = "*.gitlab-ci.yml",
},
},
},
}
end,
}
I can confirm what @dynamotn said andthat's works for me:
local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true }
I can confirm that silence the warnings.
I took a look at this after I looked at #807 since I think they might have the same root cause (missing a null check somewhere while reading in the settings). However, I wasn't able to reproduce this in Helix, since it doesn't support folding nor configuring the client capabilities that are sent to the server. In order to reproduce this issue, I'll need to go through setting up folding support for neovim in order to reproduce this issue. (For anyone whose interested in reproducing, note that neovim doesn't support folding ranges out of the box, and you will need to use a plugin or code it yourself in lua in order to enable it).
For those that still have this issue even after applying the fix, check if you have yaml-companion, it overwrites the lspconfig. Fix is to additionally pass capabilities into it explicitly:
{
"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,
},
},
},
},
},
}