Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/quicker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lua/quicker/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 22 additions & 4 deletions lua/quicker/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
30 changes: 30 additions & 0 deletions tests/display_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/snapshots/display_columns_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
README.md ┃ 7:1┃short column
README.md ┃120:45┃wide location
README.md ┃ 10┃missing column
Loading