From 1057097e1aaa12c463ca074b53f0a3740844dcbb Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Mon, 23 Dec 2024 18:45:26 -0500 Subject: [PATCH] feat: more minimal display when no items have a filename --- lua/quicker/display.lua | 34 +++++++++++++++++-------------- tests/display_spec.lua | 12 +++++++++++ tests/snapshots/display_minimal_1 | 1 + 3 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 tests/snapshots/display_minimal_1 diff --git a/lua/quicker/display.lua b/lua/quicker/display.lua index d3ee199..1c5c43e 100644 --- a/lua/quicker/display.lua +++ b/lua/quicker/display.lua @@ -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] @@ -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 diff --git a/tests/display_spec.lua b/tests/display_spec.lua index 2601b68..c3404ad 100644 --- a/tests/display_spec.lua +++ b/tests/display_spec.lua @@ -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({ diff --git a/tests/snapshots/display_minimal_1 b/tests/snapshots/display_minimal_1 new file mode 100644 index 0000000..46190e7 --- /dev/null +++ b/tests/snapshots/display_minimal_1 @@ -0,0 +1 @@ + ┃text \ No newline at end of file