-
Notifications
You must be signed in to change notification settings - Fork 218
Description
Did you check the docs and existing issues?
- I have read the docs
- I have searched the existing issues
Neovim version (nvim -v)
NVIM v0.12.0-dev-1855+gc08139d790
Operating system/version
ArchLinux
Describe the bug
When I open a file that has some slow FileType autocmd (treesitter when loads the parser for example) there is a noticeable delay, we can workaround by wrapping the autocmd callback with vim.schedule_wrap and commands like :e slow_file.c will open the buffer instantly as the parser loading (with FileType) was scheduled. Problem is that oil doesn't respect the schedule and keeps its window until the scheduled handler has finished its job.
What is the severity of this bug?
tolerable (can work around it)
Steps To Reproduce
- nvim -u repro.lua .
- select
test.c - open another c file (
:e foo.c) - there is a noticeable delay when opening with oil
Expected Behavior
I would expect it to behave like the :e command, other file-opening solutions like snacks picker/explorer doesn't have this issue. For now we can workaround by adding an extra vim.defer_fn(fn, 0) within the scheduled callback (other values than 0 like 1 or 10 doesn't do the trick, only 0 or larger values like 1000):
vim.api.nvim_create_autocmd("FileType", {
pattern = "c",
callback = function()
vim.cmd.norm("i" .. vim.fn.expand("%:."))
vim.schedule(function()
vim.defer_fn(function()
vim.wait(2000)
end, 0)
end)
end,
})Directory structure
No response
Repro
vim.pack.add { "https://github.com/stevearc/oil.nvim" }
if not vim.uv.fs_stat "test.c" then
vim.fn.writefile({}, "test.c")
end
vim.api.nvim_create_autocmd("FileType", {
pattern = "c",
callback = function()
vim.cmd.norm("i" .. vim.fn.expand("%:."))
vim.schedule(function()
vim.wait(2000)
end)
end,
})
require("oil").setup()Did you check the bug with a clean config?
- I have confirmed that the bug reproduces with
nvim -u repro.luausing the repro.lua file above.
I'd like to help to fix this but will need some guide about how opening/selecting a file works, I tried already a few things with no result.