redhat-developer / yaml-language-server

Language Server for YAML Files
MIT License
1.05k stars 257 forks source link

`[SOLVED]` RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" #912

Open Zeioth opened 1 year ago

Zeioth commented 1 year ago

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

Zeioth commented 1 year ago

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

dynamotn commented 1 year ago

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

CleoMenezesJr commented 10 months ago

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
}
alextricity25 commented 6 months ago

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,
}
Zeioth commented 6 months ago

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.

datho7561 commented 5 months ago

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

kapral18 commented 4 months ago

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