From fefd0da462c71f1cdf8830df02d28b99f2d8c077 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 8 Oct 2023 04:18:26 -0500 Subject: [PATCH] feat(nvim): add auto refresh to trouble with a hack --- dots/.config/nvim/lua/plugins/configs/trouble.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dots/.config/nvim/lua/plugins/configs/trouble.lua b/dots/.config/nvim/lua/plugins/configs/trouble.lua index 232291b8..41a001c7 100644 --- a/dots/.config/nvim/lua/plugins/configs/trouble.lua +++ b/dots/.config/nvim/lua/plugins/configs/trouble.lua @@ -38,11 +38,21 @@ return { { "xq", "TroubleToggle quickfix", desc = "Trouble: Quickfix" }, { "xt", "TodoTrouble", desc = "Trouble: Todo Items" }, }, + event = { "QuickFixCmdPre" }, dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() vim.api.nvim_create_autocmd("QuickFixCmdPost", { callback = function () - vim.cmd("Trouble quickfix") + vim.cmd.TroubleRefresh() + vim.cmd.Trouble("quickfix") + end + }) + -- HACK: Unfortuantely Neovim & Vim don't expose some C level functions to know when content in the + -- quickfix has been updated 😢. A serious issue with this is that it just tries to refresh after 200ms, + -- which may or may not work depending on how long the quickfix filtering took :/ + vim.api.nvim_create_autocmd({"CmdlineLeave", "CmdwinLeave"}, { + callback = function () + vim.defer_fn(vim.cmd.TroubleRefresh, 200) end }) require("trouble").setup({