local status_ok, trouble = pcall(require, "trouble")
if not status_ok then
    return
end

trouble.setup({
    position = "bottom",
    height = 15,
    icons = true,
    mode = "workspace_diagnostics",
    severity = nil,
    fold_open = "",
    fold_closed = "",
    action_keys = {
        close = "q",
        refresh = "r",
        jump = { "<cr>", "<tab>" },
        open_split = "x",
        open_vsplit = "v",
        preview = "p",
        close_folds = "zm",
        open_folds = "zr",
        toggle_fold = "za",
        previous = "k",
        next = "j",
    },
    auto_preview = true,
    use_diagnostic_signs = true,
})

local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }

map("n", "<leader>xx", "<cmd>TroubleToggle workspace_diagnostics<CR>", opts)
map("n", "<leader>xd", "<cmd>TroubleToggle document_diagnostics<CR>", opts)
map("n", "<leader>xq", "<cmd>TroubleToggle quickfix<CR>", opts)
map("n", "<leader>xl", "<cmd>TroubleToggle loclist<CR>", opts)
map("n", "gr", "<cmd>TroubleToggle lsp_references<CR>", opts)
