kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.16k stars 37 forks source link

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

Open Andrew15-5 opened 3 months ago

Andrew15-5 commented 3 months ago

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 ```lua 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 ```lua 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 commented 3 months ago

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

Andrew15-5 commented 3 months ago

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 commented 3 months ago

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

kevinhwang91 commented 3 months ago

Find the culprit plugin first.

JulianGodd commented 3 months ago

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.