yaml-language-server icon indicating copy to clipboard operation
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')"

Open Zeioth opened this issue 2 years ago • 7 comments

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

  1. Install yaml-language-server using mason.
  2. Open a yaml file
  3. Write it into disk

Environment

  • [ x ] Arch Linux

Zeioth avatar Aug 16 '23 17:08 Zeioth

This is one is gonna be tough to debug because it doesn't reproduce consistently, give me more time to debug.

Zeioth avatar Aug 16 '23 17:08 Zeioth

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

dynamotn avatar Aug 28 '23 08:08 dynamotn

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
}

CleoMenezesJr avatar Nov 07 '23 00:11 CleoMenezesJr

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,
}

alextricity25 avatar Mar 07 '24 22:03 alextricity25

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.

Zeioth avatar Mar 10 '24 14:03 Zeioth

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).

datho7561 avatar Mar 21 '24 18:03 datho7561

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,
            },
          },
        },
      },
    },
}

kapral18 avatar May 01 '24 08:05 kapral18