Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zeioth opened this issue Aug 16, 2023 · 7 comments

Comments

@Zeioth
Copy link

Zeioth commented Aug 16, 2023

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
Copy link
Author

Zeioth commented Aug 16, 2023

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

@dynamotn
Copy link

dynamotn commented Aug 28, 2023

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 dynamotn/neovim-config@e7fa4ca

@CleoMenezesJr
Copy link

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
Copy link

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
Copy link
Author

Zeioth commented Mar 10, 2024

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 Zeioth changed the title RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" [SOLVED] RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" Mar 15, 2024
@Zeioth Zeioth changed the title [SOLVED] RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" [SOLVED] RPC[Error] code_name = InternalError, message = "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" Mar 15, 2024
@datho7561
Copy link
Contributor

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
Copy link

kapral18 commented May 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants