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

zM and zR sometimes do change foldlevel (nvchad config) #206

Open
Andrew15-5 opened this issue Mar 14, 2024 · 5 comments
Open

zM and zR sometimes do change foldlevel (nvchad config) #206

Andrew15-5 opened this issue Mar 14, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Andrew15-5
Copy link

Andrew15-5 commented Mar 14, 2024

Neovim version (nvim -v | head -n1)

NVIM v0.9.4

Operating system/version

Pop!_OS 22.04

How to reproduce the issue

I tried using a lazy.nvim config:

config
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  }
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup {
  { -- configure LPS servers
    "neovim/nvim-lspconfig",
    dependencies = "kevinhwang91/nvim-ufo", -- enable LSP-based folds
    config = function()
      local lspconfig = require "lspconfig"
      local capabilities = vim.lsp.protocol.make_client_capabilities()
      capabilities.textDocument.foldingRange = {
        dynamicRegistration = false,
        lineFoldingOnly = true,
      }

      lspconfig.lua_ls.setup {
        capabilities = capabilities,
      }

      require("ufo").setup()
    end,
  },

  { -- folds
    "kevinhwang91/nvim-ufo",
    dependencies = "kevinhwang91/promise-async",
    config = function()
      vim.o.foldcolumn = "1"
      vim.o.foldlevel = 99
      vim.o.foldlevelstart = 99
      vim.o.foldenable = true

      require("ufo").setup {}

      vim.keymap.set("n", "zR", require("ufo").openAllFolds)
      vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
    end,
  },

  {
    "williamboman/mason.nvim",
    cmd = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUpdate" },
    dependencies = "williamboman/mason-lspconfig.nvim",
    lazy = false,
    config = function()
      local opts = {
        ensure_installed = { "lua-language-server" },
        automatic_installation = true,
      }
      -- vim.env.PATH = '/root/.local/share/nvim/mason/bin:' .. vim.env.PATH
      require("mason").setup(opts)
      vim.api.nvim_create_user_command("MasonInstallAll", function()
        if opts.ensure_installed and #opts.ensure_installed > 0 then
          vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " "))
        end
      end, {})
    end,
  },
}

for a bit, and it looks like everything is fine. But I'm using nvchad v2.0 and with its minimal config:

config
return {
  { -- configure LPS servers
    "neovim/nvim-lspconfig",
    dependencies = "kevinhwang91/nvim-ufo", -- enable LSP-based folds
    config = function()
      local lspconfig = require "lspconfig"
      local capabilities = vim.lsp.protocol.make_client_capabilities()
      capabilities.textDocument.foldingRange = {
        dynamicRegistration = false,
        lineFoldingOnly = true,
      }

      lspconfig.lua_ls.setup {
        capabilities = capabilities,
      }

      require("ufo").setup()
    end,
  },

  { -- folds
    "kevinhwang91/nvim-ufo",
    dependencies = "kevinhwang91/promise-async",
    config = function()
      vim.o.foldcolumn = "1"
      vim.o.foldlevel = 99
      vim.o.foldlevelstart = 99
      vim.o.foldenable = true

      require("ufo").setup {}

      vim.keymap.set("n", "zR", require("ufo").openAllFolds)
      vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
    end,
  },
}

It sometimes/eventually does change the fold level. And the main problem is that I have no idea why this happens.

nvim-ufo.zip

cd /tmp
wget archive
unzip nvim-ufo.zip
cd nvim-ufo
just

Inside the container run j and then try zM and previously saved echo &foldlevel which eventually will change to 0. If didn't change then exit and repeat (I didn't even save).

Expected behavior

The foldlevel should always be the same after pressing zM or zR.

Actual behavior

The value can change, which is seemingly random, but normally happens on the first or second try.

@Andrew15-5 Andrew15-5 added the bug Something isn't working label Mar 14, 2024
@Andrew15-5
Copy link
Author

I will try reducing the core config later and hopefully will see what is causing the issue.

@Andrew15-5
Copy link
Author

It looks like this is the culprit:

opt.timeoutlen = 400
-- Time in milliseconds to wait for a mapped sequence to complete (default 1000).

It looks like 450 is too small and 500 is big enough for the bug to not appear. The repo does have a few 400 matches and a few 500 matches. Can you tell what is the problem?

I'm not sure, but it probably has something to do with which key and how quickly I need to execute a keymap. Yeah, I changed it between 10 and 1000 and the difference is visible. But how is this connected to the ufo's use of zM?

@Andrew15-5
Copy link
Author

Nope, for mrcjkb/rustaceanvim 500 isn't enough... But it looks like 700 is.

@kevinhwang91
Copy link
Owner

Find the culprit plugin first.

@JulianGodd
Copy link

I have this same behavior in my nvim config started from kickstart.nvim. Removing nvim-ufo removes the zM behavior although this could be a plugin interaction.

Strangely, when I bind zm (lowercase) to closeFoldsWith(1), typing it with a delay sets the foldlevel to 98 (default 99).

Will update when I have more time to make a minimal config demonstrating the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants