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

error when opening fold #186

Closed lobneroO closed 5 months ago

lobneroO commented 6 months ago

Neovim version (nvim -v | head -n1)

NVIM v0.9.4

Operating system/version

Arch Linux

How to reproduce the issue

  1. Install fresh neovim
  2. Install the kickstarter repo
  3. In the kickstarter's init.lua file, comment out the line -- { import = 'custom.plugns' }, (in my version it is line 232)
  4. Add the file ufo.lua file for installation, as suggested by the kickstarter project (on Linux this would be at ~/.config/nvim/lua/custom/plugins/ufo.lua)
  5. Setup the new .lua file:

I took this supposedly minimal working example from issue #117 , answer by @Rolv-Apneseth

return {
    "kevinhwang91/nvim-ufo",
    event = "BufRead",
    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()
    end,
}
  1. Open a file with neovim, go to an area that can be folded
  2. Close the fold and reopen it

Expected behavior

The code folds, the first line before the fold is still readable and code within the folded area disappears (i.e. is fold is closed)

Actual behavior

first line of the fold is replaced by a 0, error

ufo: Error executing lua: ...al/share/nvim/lazy/nvim-ufo/lua/ufo/model/foldbuffer.lua:54: attempt to call method 'syntax' (a string value) stack traceback: ...

(sorry, the stack is cut off in my editor. I don't know how to print it elsewhere) image

danpf commented 6 months ago

just ran into this, seems like the defer_fn is the cause.

if you remove the defer_fn guard from nvim-treesitter init, it should work again. I'm not sure how to retain that functionality though.

https://github.com/nvim-lua/kickstart.nvim/blob/4d0dc8d4b1bd6b94e59f7773158149bb1b0ee5be/init.lua#L423

nolanking90 commented 6 months ago

I can duplicate this with a minimal config (just ufo and treesitter installed) using packer instead of lazy.nvim. However, it only happens the first time I open a file after installing treesitter. Closing and reopening neovim fixes it.

My ufo config:

vim.o.foldcolumn = '1'
vim.o.foldlevel = 99
vim.o.foldlevelstart = 99
vim.o.foldenable = true
require('ufo').setup()

My treesitter config:

require'nvim-treesitter.configs'.setup {
  ensure_installed = { "lua", "vim", "vimdoc", "query" , "latex", "python"},
  sync_install = false,
  auto_install = false,
  highlight = { enable = true },
  indent = { enable = true },
}

Here's the full stack trace:

Error in decoration provider ufo.end:
Error executing lua: .../pack/packer/start/nvim-ufo/lua/ufo/model/foldbuffer.lua:54: attempt to call method 'syntax' (a string value)
stack traceback:
        .../pack/packer/start/nvim-ufo/lua/ufo/model/foldbuffer.lua:54: in function 'syntax'
        ...im/site/pack/packer/start/nvim-ufo/lua/ufo/decorator.lua:218: in function 'getVirtTextAndCloseFold'
        ...im/site/pack/packer/start/nvim-ufo/lua/ufo/decorator.lua:102: in function <...im/site/pack/packer/start/nvim-ufo/lua/ufo/decorator.lua:66>
malishengo commented 5 months ago

same issue here!

kevinhwang91 commented 5 months ago

I can duplicate this with a minimal config (just ufo and treesitter installed) using packer instead of lazy.nvim.

@nolanking90 How can I reproduce it?

kevinhwang91 commented 5 months ago

Without reproduced steps, nobody can help.

nolanking90 commented 5 months ago

I can duplicate this with a minimal config (just ufo and treesitter installed) using packer instead of lazy.nvim.

@nolanking90 How can I reproduce it?

Using packer, delete treesitter, then reinstall treesitter. Then open a file you want to use folding on. run :TSInstall and :TSBufEnable highlight if it doesn’t automatically, then try to use folding.