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

YAML folds not working #72

Closed
windowsrefund opened this issue Sep 2, 2022 · 6 comments
Closed

YAML folds not working #72

windowsrefund opened this issue Sep 2, 2022 · 6 comments
Labels
invalid This doesn't seem right

Comments

@windowsrefund
Copy link

Neovim version (nvim -v | head -n1)

0.7.2

Operating system/version

Who cares

How to reproduce the issue

Open any YAML file

Expected behavior

Expect folds to work

Actual behavior

Screenshot_2022-09-01_23-51-06

Tried every configuration example I can find on this site including #21 but nothing works.

@windowsrefund windowsrefund added the bug Something isn't working label Sep 2, 2022
@kevinhwang91
Copy link
Owner

-- Option 2: nvim lsp as LSP client
-- 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
}

@kevinhwang91 kevinhwang91 added invalid This doesn't seem right and removed bug Something isn't working labels Sep 2, 2022
@windowsrefund
Copy link
Author

That does not work. Have you opened a yaml file yourself with that setup (with yamlls installed and attached to the buffer)?

@kevinhwang91
Copy link
Owner

Work for me. Debug yourself to make sure capabilities.textDocument contains foldingRange.

@msva
Copy link

msva commented Oct 28, 2022

Acttually, I had exactly same error with exactly same yaml langserver.

Problem was exactly in the fact that I missed to pass capabilities to exactly that langserver.

FYI, @windowsrefund

@costa-simulatedreality
Copy link

costa-simulatedreality commented Jun 29, 2023

I have added this lines of code to include the capabilities in the available language servers (this file is in my .config/lvim/after/plugin/nvim-ufo.lua)

vim.o.foldcolumn = '1' -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]

-- 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 = require("lspconfig").util.available_servers() -- 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

local builtin = require("statuscol.builtin")
require("statuscol").setup({
  relculright = true,
  segments = {
    { text = { builtin.foldfunc }, click = "v:lua.ScFa" },
    { text = { "%s" }, click = "v:lua.ScSa" },
    { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
  },
})

require('ufo').setup()

But for some reason I keep getting this "Request textDocument/foldingRange failed with message: Cannot read properties of undefined (reading 'lineFoldingOnly')" error message every time I open a yaml file.
When I do check if the ymlls server is available, it in fact is!
image

How can I check if the capability has been added to my ls on runtime (i.e. after lunarvim has gone through the whole configuration setup) ?

@kapral18
Copy link

kapral18 commented May 1, 2024

If you added the capabilities but still experience the issue, most like you have another plugin that overwrites your lsp config like yaml-chamption https://github.com/someone-stole-my-name/yaml-companion.nvim/blob/4de1e1546abc461f62dee02fcac6a02debd6eb9e/lua/yaml-companion/config.lua#L15.

Issue here someone-stole-my-name/yaml-companion.nvim#37.

For yaml-companion one of the fixes is to additionally pass it again into the plugin

like

  {
    "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
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants