stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.82k stars 109 forks source link

bug: Not work if opening dir from quickfix path entry with bqf/trouble plugin used #373

Open towry opened 4 months ago

towry commented 4 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

nightly

Operating system/version

macOs

Describe the bug

When opening dir from quickfix path entry, it works as expected if no quickfix plugin installed (like nvim-bqf or trouble.nvim).

The logs of the au events is as below:

OK bufadd3
3bufreadcmd (BufReadCmd on pattern '*')
Load from bufreadcmd
load oil

But with quickfix plugin enabled, the log is:

3bufreadcmd (BufReadCmd on pattern '*')
OK bufadd3 

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. nvim --clean -u init.lua
  2. press <space>, to open folders picker.
  3. press <c-q> send folders to quickfix window.
  4. in trouble quickfix window, press enter to open dir path entry.

Expected Behavior

Should work with other quickfix plugin

Directory structure

no need

Repro

vim.g.mapleader = " "

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    { "nvim-lua/plenary.nvim" },
    { "nvim-telescope/telescope-file-browser.nvim" },
    {
        "folke/trouble.nvim",
        ft = "qf",
        branch = "dev",
        enabled = true,
        cmd = {
            "Trouble",
            "TroubleClose",
            "TroubleToggle",
            "TroubleRefresh",
        },
        opts = {},
        init = function()
            vim.api.nvim_create_autocmd("FileType", {
                pattern = "qf",
                callback = function(args)
                    local trouble = require("trouble")
                    local bufnr = args.buf
                    vim.defer_fn(function()
                        local winid = vim.fn.bufwinid(bufnr)
                        if winid == -1 then
                            return
                        end
                        vim.api.nvim_win_close(winid, true)
                        trouble.open("quickfix")
                    end, 0)
                end,
            })
        end,
    },

    { "stevearc/oil.nvim", opts = {
        default_file_explorer = true,
    } },
    {
        "nvim-telescope/telescope.nvim",
        keys = {
            {
                "<leader>,",
                [[:lua require('telescope').extensions.file_browser.file_browser({cwd='~'})<cr>]],
                desc = "telescope folders",
            },
        },
        cmd = { "Telescope" },
        config = function()
            require("telescope").setup({})
            require("telescope").load_extension("file_browser")
        end,
    },
}

require("lazy").setup({
    spec = plugins,
    root = root .. "/plugins",
    defaults = {
        lazy = false,
    },
    state = root .. "/lazy/state.json",
    performance = {
        cache = {
            enabled = false,
        },
    },
})

-- add anything else here

Did you check the bug with a clean config?

stevearc commented 4 months ago

Confirmed bug. Something is going wrong in the process of renaming the <dir> buffer to oil://<dir> and the BufReadCmd autocmd is not getting fired. When I've seen this behavior before it's been because of autocmd nesting that prevents BufReadCmd from being dispatched. After poking around for a while, I still haven't been able to figure out the exact cause. Putting this on the back burner