Skip to content

bug: select action blocks ui with slow scheduled FileType autocommand #699

@lopi-py

Description

@lopi-py

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

  1. nvim -u repro.lua .
  2. select test.c
  3. open another c file (:e foo.c)
  4. 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.lua using 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions