From 2721da8b8192cb5860b2aac4db22ed1e71c74f62 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Sat, 18 Apr 2026 13:51:11 +0200 Subject: [PATCH] get qflist on errors with message as well --- nvim/.config/nvim/init.lua | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 12e602c..b38b87a 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -36,13 +36,31 @@ do local orig = debug.traceback ---@diagnostic disable-next-line: duplicate-set-field - debug.traceback = function(...) - local trace = full_trace() - local orig_trace = orig(...) -- TODO remove. find message instead + debug.traceback = function(thread, message, level) + local trace = vim.split(full_trace(), "\n") + local orig_trace = orig(thread, message, level) + if type(thread) ~= 'thread' then + level = message + message = thread + end + assert(type(message) == 'nil' or type(message) == 'string') + local qflist_items = vim.split(message, "\n") + + -- doing this to remove truncated file location at the start of the error message + for i, msg in ipairs(qflist_items) do + local match = string.match(msg, ".*:%s*(.*)") + if match ~= nil then + qflist_items[i] = match + end + end + + for _, loc in ipairs(trace) do + table.insert(qflist_items, loc) + end vim.fn.setqflist({}, "a", { title = "Traceback", - lines = vim.split(trace, "\n"), + lines = qflist_items, }) return orig_trace