folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.12k stars 172 forks source link

feature: override default quickfix window #428

Closed ofseed closed 1 month ago

ofseed commented 1 month ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

Though trouble.nvim provides a nice quickfix window ui, many plugins or nvim itself calls :copen to open the quickfix window, so it's troublesome to utilize trouble for quickfix.

Describe the solution you'd like

I found a hack that could hijack the quickfix window.

vim.api.nvim_create_autocmd("FileType", {
  pattern = "qf",
  callback = function(args)
    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,
})

Describe alternatives you've considered

Though this hack works, occasionally it will "flicker". Not sure if there exists a better way to handle this.

Additional context

I'm wondering whether trouble.nvim could provide an option to do something like this, or provide this hack directly.

folke commented 1 month ago

Best I could come up with: https://github.com/folke/trouble.nvim/blob/dev/docs/examples.md#open-trouble-quickfix-when-the-qf-list-opens