Closed tan-wei closed 10 months ago
I tried your config above and couldn't reproduce (both rust and c++ work well). I believe it's not ufo's bug.
UFO_LOG=debug nvim
;tail -f ~/.cache/nvim/ufo.log
;Thanks. After several try with restart neovim and waiting for LSP complete parsing, it works. I think I should wait for it complete patiently.
Thanks for your reply. @kevinhwang91 's method is helpful in the future when I meet issue.
Plugin like LSP progress indicator may be useful for a large repo.
Got it. So if LSP progess is not finished, the selected provider will be nil
in nvim-ufo
?
I find it behave strange on my other computer which runs on Windows. The configure is just the same, but after I open a Rust project, the log would be:
[23-08-22 12:38:42] [DEBUG] init.lua:128 : attach bufnr: 1
[23-08-22 12:38:43] [INFO] init.lua:89 : providers: { "treesitter", "indent" }
[23-08-22 12:38:44] [DEBUG] init.lua:128 : attach bufnr: 4
[23-08-22 12:38:44] [DEBUG] init.lua:128 : attach bufnr: 5
[23-08-22 12:38:45] [DEBUG] init.lua:53 : requestFoldingRange({ "treesitter", "indent" }, 1) has elapsed: 2199ms
[23-08-22 12:38:45] [DEBUG] init.lua:83 : update fold again for bufnr: 1
The buffer 4 is the opened Rust file, but it does not update fold, and after LSP finished, I can confirm that the selected provider is still nil
:
Seems that nvim-ufo
does not update buffer 4 then. And I try to use command UfoEnable
, UfoDisable
, UfoEnableFold
, UfoAttach
, etc., no new log is logged.
Got it. So if LSP progess is not finished, the selected provider will be nil in nvim-ufo?
Only assign value in line 95. So nil
is expected in the request.
I find it behave strange on my other computer which runs on Windows. The configure is just the same, but after I open a Rust project, the log would be:
From your log, no request for bufnr 4 which is attached, not sure if it is your complete log.
Yes, it is a complete log. I upload the whole one here, and you can see I've tried sever times by restart neovim with opening the same file: ufo.log
OK, I find a phenomenon:
auto-session
(https://github.com/rmagatti/auto-session) to manage session. If the opened file is recovered by auto-session
, nvim-ufo
will not try to update the buffernvim xxx.rs
, nvim-ufo
will work wellSo I think it is related to auto-session
's recover session behave. When does nvim-ufo
try to update the buffer?
Here is the latest log: ufo.log
Look like BufDetach
event is fired. Change log level and debug yourself, no idea about your ENV.
UFO_LOG=trace nvim
OK, I'll try, hope I can find a workaround for this. Thanks.
But I still upload the trace log here: ufo.log
Thanks, from the trace log I found a bug, please update the code, hope that commit should help you.
OK. Thanks again!
Neovim version (nvim -v | head -n1)
NVIM v0.10.0-dev-900+g4a1fb37108
Operating system/version
archlinux
How to reproduce the issue
-- Setting vim.o.foldcolumn = '1' vim.o.foldlevel = 99 vim.o.foldlevelstart = 99 vim.o.foldenable = true
local status_ok, ufo = pcall(require, "ufo") if not status_ok then return end
local ftMap = { vim = "indent", python = { "indent" }, git = "", lua = { "lsp", "treesitter" }, rust = { "lsp", "treesitter" }, c = { "lsp", "treesitter" }, cpp = { "lsp", "treesitter" }, }
ufo.setup { open_fold_hl_timeout = 150, close_fold_kinds = { "imports", "comment" }, preview = { win_config = { border = { "", "─", "", "", "", "─", "", "" }, winhighlight = "Normal:Folded", winblend = 0, }, mappings = { scrollU = "",
scrollD = "",
jumpTop = "[",
jumpBot = "]",
},
},
provider_selector = function(bufnr, filetype, buftype)
return ftMap[filetype] or { "treesitter", "indent" }
end,
}
vim.keymap.set("n", "zR", ufo.openAllFolds) vim.keymap.set("n", "zM", ufo.closeAllFolds) vim.keymap.set("n", "zr", ufo.openFoldsExceptKinds) vim.keymap.set("n", "zm", ufo.closeFoldsWith) -- closeAllFolds == closeFoldsWith(0) vim.keymap.set("n", "K", function() local winid = ufo.peekFoldedLinesUnderCursor() if not winid then vim.lsp.buf.hover() end end)