Skip to content

Commit

Permalink
feat: more minimal display when no items have a filename
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 23, 2024
1 parent f2eda24 commit 1057097
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lua/quicker/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ function M.quickfixtextfunc(info)
local col_width = get_cached_qf_col_width(info.id, items)
local lnum_fmt = string.format("%%%ds", lnum_width)
local prefixes = calc_whitespace_prefix(items)
local no_filenames = col_width == 0

local function get_virt_text(lnum)
-- If none of the quickfix items have filenames, we don't need the lnum column and we only need
-- to show a single delimiter. Technically we don't need any delimiter, but this maintains some
-- of the original qf behavior while being a bit more visually appealing.
if no_filenames then
return { { b.vert, "Delimiter" } }
else
return {
{ b.vert, "Delimiter" },
{ lnum_fmt:format(lnum), "QuickFixLineNr" },
{ b.vert, "Delimiter" },
}
end
end

for i = info.start_idx, info.end_idx do
local item = items[i]
Expand Down Expand Up @@ -489,30 +505,18 @@ function M.quickfixtextfunc(info)
-- Matching line
local lnum = item.lnum == 0 and " " or item.lnum
local filename = rpad(M.get_filename_from_item(item), col_width)
table.insert(locations, {
{ b.vert, "Delimiter" },
{ lnum_fmt:format(lnum), "QuickFixLineNr" },
{ b.vert, "Delimiter" },
})
table.insert(locations, get_virt_text(lnum))
table.insert(ret, filename .. EM_QUAD .. remove_prefix(item.text, prefixes[item.bufnr]))
elseif user_data.lnum then
-- Non-matching line from quicker.nvim context lines
local filename = string.rep(" ", col_width)
table.insert(locations, {
{ b.vert, "Delimiter" },
{ lnum_fmt:format(user_data.lnum), "QuickFixLineNr" },
{ b.vert, "Delimiter" },
})
table.insert(locations, get_virt_text(user_data.lnum))
table.insert(ret, filename .. EM_QUAD .. remove_prefix(item.text, prefixes[item.bufnr]))
else
-- Other non-matching line
local lnum = item.lnum == 0 and " " or item.lnum
local filename = rpad(M.get_filename_from_item(item), col_width)
table.insert(locations, {
{ b.vert, "Delimiter" },
{ lnum_fmt:format(lnum), "QuickFixLineNr" },
{ b.vert, "Delimiter" },
})
table.insert(locations, get_virt_text(lnum))
invalid_filenames[#locations] = true
table.insert(ret, filename .. EM_QUAD .. remove_prefix(item.text, prefixes[item.bufnr]))
end
Expand Down
12 changes: 12 additions & 0 deletions tests/display_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ a.describe("display", function()
test_util.assert_snapshot(0, "display_long_1")
end)

a.it("renders minimal line when no filenames in results", function()
vim.fn.setqflist({
{
text = "text",
},
})
vim.cmd.copen()
-- Wait for highlights to be applied
sleep(50)
test_util.assert_snapshot(0, "display_minimal_1")
end)

a.it("sets signs for diagnostics", function()
local bufnr = vim.fn.bufadd(test_util.make_tmp_file("sign_test.txt", 10))
vim.fn.setqflist({
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/display_minimal_1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 ┃text

0 comments on commit 1057097

Please sign in to comment.