kevinhwang91 / nvim-ufo

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

Just curious: Why doesn't ufo play well with PackerSync? #97

Closed garaiza-93 closed 1 year ago

garaiza-93 commented 1 year ago

Neovim version (nvim -v | head -n1)

NVIM v0.9.0-dev-124-gbd7ca10fd

Operating system/version

Manjaro

How to reproduce the issue

cat mini.lua

--In plugins.lua for all packer plugins...
 use { 'kevinhwang91/nvim-ufo', requires = 'kevinhwang91/promise-async' }
--In another file where ufo is used...
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
  dynamicRegistration = false,
  lineFoldingOnly = true,
}
--...lsp server configs...
require('ufo').setup({
  provider_selector = function(bufnr, filetype, buftype)
    return {'lsp', 'treesitter'}
  end
})
  1. Install the plugin using PackerSync, using the above configuration
  2. Close and reopen neovim
  3. Error in packer_compiled: ...site/pack/packer/start/nvim-ufo/lua/ufo/fold/manager.lua:89: attempt to index field 'buffers' (a nil value)

Expected behavior

I expect to be able to open neovim without this confusing error. I say that it is confusing, because after double-checking the source code, I don't think this should be an issue.

Actual behavior

Error in packer_compiled: ...site/pack/packer/start/nvim-ufo/lua/ufo/fold/manager.lua:89: attempt to index field 'buffers' (a nil value)

Note: I am aware that from another issue, using PackerCompile followed by PackerUpdate tends to sidestep this error. However, I am curious as to why using PackerSync is an issue.

kevinhwang91 commented 1 year ago

Can't reproduce it, make sure that the mini config with packer.nvim still causes the issue.

yizhenAllen commented 11 months ago

I have this problem too, I install the plugin via lazy.nvim and here is my config:

return {
  'kevinhwang91/nvim-ufo',
  dependencies = 'kevinhwang91/promise-async',
  config = function()
    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

    -- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself
    vim.keymap.set('n', 'zR', require('ufo').openAllFolds)
    vim.keymap.set('n', 'zM', require('ufo').closeAllFolds)
  end,
}

I reboot neovim, seems everything's good, checkhealth's good, then I open a python file and type zM, and the following error shows(typing zR shows the same error):

E5108: Error executing lua: ....local/share/nvim/lazy/nvim-ufo/lua/ufo/fold/manager.lua:89: attempt to index field 'buffers' (a nil value)
stack traceback:
    ....local/share/nvim/lazy/nvim-ufo/lua/ufo/fold/manager.lua:89: in function 'get'
    ...izhen/.local/share/nvim/lazy/nvim-ufo/lua/ufo/action.lua:107: in function <...izhen/.local/share/nvim/lazy/nvim-ufo/lua/ufo/action.lua:104>

Could anyone pls tell me what should I do?

kevinhwang91 commented 11 months ago

Don't lazy load.

yizhenAllen commented 11 months ago

I added lazy = false, after dependencies and before config, still not working though.

Now I use the following config to fold, which works well, leave it here as a reference:

vim.o.foldenable = true
opt.foldmethod = "expr"
opt.foldexpr = "nvim_treesitter#foldexpr()" --use treesitter to fold
vim.o.foldlevel = 99
vim.o.foldlevelstart = 99

-- add following or files opened by telescope cannot be folded
vim.api.nvim_create_autocmd({ "BufEnter" }, { pattern = { "*" }, command = "normal zx", })
juanmagalhaes commented 11 months ago

I'm having the same issue here. Any news on this @yizhenAllen ?

yizhenAllen commented 11 months ago

I'm having the same issue here. Any news on this @yizhenAllen ?

No hah, now I simply use treesitter to fold, you can check my config above if you're interested.

juanmagalhaes commented 11 months ago

@yizhenAllen I managed to put it to work just now. This was the missing bit that apparently is necessary:

  {
    "kevinhwang91/nvim-ufo",
    dependencies = "kevinhwang91/promise-async",
    event = "VeryLazy",
    config = function(_, opts)
      -- This piece in the config right here
      require("ufo").setup(opts)
    end
  }
yizhenAllen commented 11 months ago

@yizhenAllen I managed to put it to work just now. This was the missing bit that apparently is necessary:

  {
    "kevinhwang91/nvim-ufo",
    dependencies = "kevinhwang91/promise-async",
    event = "VeryLazy",
    config = function(_, opts)
      -- This piece in the config right here
      require("ufo").setup(opts)
    end
  }

It works pretty well, thank you! event = "VeryLazy" is the point rather than lazy = false