vim.api.nvim_create_autocmd("BufRead", {
  callback = function(ev)
    if vim.bo[ev.buf].buftype == "quickfix" then
      vim.schedule(function()
        vim.cmd([[cclose]])
        vim.cmd([[Trouble qflist open focus=true]])
      end)
    end
  end,
})

return {
    'folke/trouble.nvim',
    dependencies = {"nvim-tree/nvim-web-devicons"},
    opts = {
        action_keys = {
            close = {"q", "<Esc>"},
            jump = {"<cr>"},
            toggle_fold = {"<tab>"},
        },
        warn_no_results = false,
        open_no_results = true,
        auto_focus = true,
        max_items = 100000000000000,
    },
    keys = {
        {
            "<leader>d",
            "<cmd>Trouble diagnostics toggle focus=true<cr>",
            desc = "Diagnostics (Trouble)",
        },
        {
            "<leader>q",
            "<cmd>Trouble close<cr>",
            desc = "Close Trouble",
        },
        {
            "<C-/>",
            function ()
                vim.cmd(":vimgrep // %")
                vim.cmd(":Trouble quickfix focus=true")
            end,
            desc = "Send search to Trouble",
        },
    },
    lazy = false
}
