From 85c1c9622461a910b08af6022294b29a099126aa Mon Sep 17 00:00:00 2001 From: beedware Date: Sun, 20 Sep 2026 02:49:15 +0100 Subject: [PATCH] feat: support showing columns in quickfix Resolves: #45 --- doc/quicker.txt | 2 ++ lua/quicker/config.lua | 4 ++++ lua/quicker/display.lua | 26 ++++++++++++++++++++++---- tests/display_spec.lua | 30 ++++++++++++++++++++++++++++++ tests/snapshots/display_columns_1 | 3 +++ 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 tests/snapshots/display_columns_1 diff --git a/doc/quicker.txt b/doc/quicker.txt index b7de832..632779e 100644 --- a/doc/quicker.txt +++ b/doc/quicker.txt @@ -37,6 +37,8 @@ OPTIONS *quicker-option }, -- Keep the cursor to the right of the filename and lnum columns constrain_cursor = true, + -- Display quickfix item column numbers after line numbers + show_column = false, highlight = { -- Use treesitter highlighting treesitter = true, diff --git a/lua/quicker/config.lua b/lua/quicker/config.lua index 77a1444..d207a1c 100644 --- a/lua/quicker/config.lua +++ b/lua/quicker/config.lua @@ -25,6 +25,8 @@ local default_config = { }, -- Keep the cursor to the right of the filename and lnum columns constrain_cursor = true, + -- Display quickfix item column numbers after line numbers + show_column = false, highlight = { -- Use treesitter highlighting treesitter = true, @@ -77,6 +79,7 @@ local default_config = { ---@field keys quicker.Keymap[] ---@field use_default_opts boolean ---@field constrain_cursor boolean +---@field show_column boolean ---@field highlight quicker.HighlightConfig ---@field follow quicker.FollowConfig ---@field edit quicker.EditConfig @@ -93,6 +96,7 @@ local M = {} ---@field keys? quicker.Keymap[] Keymaps to set for the quickfix buffer ---@field use_default_opts? boolean Set to false to disable the default options in `opts` ---@field constrain_cursor? boolean Keep the cursor to the right of the filename and lnum columns +---@field show_column? boolean Display quickfix item column numbers after line numbers ---@field highlight? quicker.SetupHighlightConfig Configure syntax highlighting ---@field follow? quicker.SetupFollowConfig Configure cursor following ---@field edit? quicker.SetupEditConfig diff --git a/lua/quicker/display.lua b/lua/quicker/display.lua index 2a60b5b..063e4ad 100644 --- a/lua/quicker/display.lua +++ b/lua/quicker/display.lua @@ -407,10 +407,22 @@ end local function get_lnum_width(items) local max_len = 2 local max = 99 - for _, item in ipairs(items) do - if item.lnum > max then - max_len = tostring(item.lnum):len() - max = item.lnum + if config.show_column then + for _, item in ipairs(items) do + if item.lnum > 0 then + local lnum = tostring(item.lnum) + if item.col and item.col > 0 then + lnum = string.format("%s:%d", lnum, item.col) + end + max_len = math.max(max_len, lnum:len()) + end + end + else + for _, item in ipairs(items) do + if item.lnum > max then + max_len = tostring(item.lnum):len() + max = item.lnum + end end end return max_len @@ -519,6 +531,9 @@ function M.quickfixtextfunc(info) if item.valid == 1 then -- Matching line local lnum = item.lnum == 0 and " " or item.lnum + if config.show_column and item.col and item.col > 0 then + lnum = string.format("%d:%d", item.lnum, item.col) + end local filename = rpad(M.get_filename_from_item(item), col_width) table.insert(locations, get_virt_text(lnum)) table.insert(ret, filename .. EM_QUAD .. trimmed_text) @@ -530,6 +545,9 @@ function M.quickfixtextfunc(info) else -- Other non-matching line local lnum = item.lnum == 0 and " " or item.lnum + if config.show_column and item.col and item.col > 0 then + lnum = string.format("%d:%d", item.lnum, item.col) + end local filename = rpad(M.get_filename_from_item(item), col_width) table.insert(locations, get_virt_text(lnum)) invalid_filenames[#locations] = true diff --git a/tests/display_spec.lua b/tests/display_spec.lua index c3404ad..cd0176d 100644 --- a/tests/display_spec.lua +++ b/tests/display_spec.lua @@ -49,6 +49,36 @@ a.describe("display", function() test_util.assert_snapshot(0, "display_1") end) + it("renders quickfix items with columns", function() + config.show_column = true + local bufnr = vim.fn.bufadd("README.md") + vim.fn.setqflist({ + { + bufnr = bufnr, + text = "short column", + lnum = 7, + col = 1, + valid = 1, + }, + { + bufnr = bufnr, + text = "wide location", + lnum = 120, + col = 45, + valid = 1, + }, + { + bufnr = bufnr, + text = "missing column", + lnum = 10, + col = 0, + valid = 1, + }, + }) + vim.cmd.copen() + test_util.assert_snapshot(0, "display_columns_1") + end) + a.it("truncates long filenames", function() config.max_filename_width = function() return 10 diff --git a/tests/snapshots/display_columns_1 b/tests/snapshots/display_columns_1 new file mode 100644 index 0000000..55102b3 --- /dev/null +++ b/tests/snapshots/display_columns_1 @@ -0,0 +1,3 @@ +README.md ┃ 7:1┃short column +README.md ┃120:45┃wide location +README.md ┃ 10┃missing column