From 010d2f096ef3dd7b8b18c9127cf404f4dccd90be Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Thu, 16 Oct 2025 03:33:32 +0200 Subject: [PATCH] feat: improve quickfixlist window --- lua/core/autocommands.lua | 39 +++++++++++++++++++++++++++++++ lua/core/mappings.lua | 3 +++ lua/core/options.lua | 49 +++++++++++++++++++++++++++++++++++++-- syntax/qf.vim | 29 +++++++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 syntax/qf.vim diff --git a/lua/core/autocommands.lua b/lua/core/autocommands.lua index 30bae29..df7158e 100644 --- a/lua/core/autocommands.lua +++ b/lua/core/autocommands.lua @@ -1,3 +1,42 @@ +vim.fn.sign_define("QfError", { text = "E", texthl = "DiagnosticError" }) +vim.fn.sign_define("QfWarn", { text = "W", texthl = "DiagnosticWarn" }) +vim.fn.sign_define("QfInfo", { text = "I", texthl = "DiagnosticInfo" }) +vim.fn.sign_define("QfNote", { text = "N", texthl = "DiagnosticHint" }) + +vim.api.nvim_create_autocmd("FileType", { + desc = "Add signs to quickfix entries", + pattern = "qf", + callback = function(event) + vim.fn.sign_unplace("quickfix_signs") + local qflist = vim.fn.getqflist() + require("log").debug(vim.inspect(qflist)) + for i, item in ipairs(qflist) do + if item.valid == 1 then + local sign_name = nil + if item.type == "E" then + sign_name = "QfError" + elseif item.type == "W" then + sign_name = "QfWarn" + elseif item.type == "I" then + sign_name = "QfInfo" + elseif item.type == "N" then + sign_name = "QfNote" + end + + if sign_name then + vim.fn.sign_place( + 0, + "quickfix_signs", + sign_name, + event.buf, + { lnum = i } + ) + end + end + end + end, +}) + vim.api.nvim_create_autocmd("FileType", { pattern = "help", callback = function() diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index c7ee999..d1dc43c 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -146,6 +146,9 @@ vim.keymap.set("n", "r", function() end end) +vim.keymap.set("n", "]c", ":cn") +vim.keymap.set("n", "[c", ":cp") + -- Default bindings that are good to know: -- insert mode: -- - indent, see :h i_CTRL-T diff --git a/lua/core/options.lua b/lua/core/options.lua index 01e37b3..01fa4b1 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -149,5 +149,50 @@ vim.opt.statusline = " %{expand('%:.')}%4( %m%) %{%v:lua._status_line_git()%} %= .. " %{&filetype} %-6.6{&fileencoding}" .. " %-4.4{&fileformat} %4.4(%p%%%)%6.6l:%-3.3v" -vim.cmd("syntax on") -vim.cmd("filetype plugin indent on") +function _G._quickfix_text_func(info) + local items + if info.quickfix == 1 then + items = vim.fn.getqflist({ id = info.id, items = 1 }).items + else + items = vim.fn.getloclist(info.winid, { id = info.id, items = 1 }).items + end + + local lines = {} + for i = info.start_idx, info.end_idx do + local item = items[i] + local line = "" + + local name = "" + if item.bufnr ~= 0 then + name = vim.fn.bufname(item.bufnr) + end + if vim.fn.strchars(name) == 0 then + name = " " + end + line = line .. name + + if item.lnum > 0 then + line = line .. ":" .. item.lnum + if item.col > 0 then + line = line .. ":" .. item.col + end + line = line .. ": " + end + + line = line .. item.text + table.insert(lines, line) + end + + return lines +end + +vim.cmd [[ + syntax on + filetype plugin indent on + + function! QuickfixTextFunc(info) abort + return v:lua._quickfix_text_func(a:info) + endfunction + + set quickfixtextfunc=QuickfixTextFunc +]] diff --git a/syntax/qf.vim b/syntax/qf.vim new file mode 100644 index 0000000..301d852 --- /dev/null +++ b/syntax/qf.vim @@ -0,0 +1,29 @@ +if exists("b:current_syntax") + finish +endif + +syntax clear + +" syntax match qfError "\c\:\@=" +" syntax match qfWarn "\c\:\@=" +" syntax match qfInfo "\c\:\@=" +" syntax match qfNote "\c\<\(note\|hint\)\>:\@=" +" syntax match qfPassed "\c\<\(ok\|passed\)\>" +" syntax match qfFailed "\c\<\fail\(ed\|ure\)\?s\?\>" + +syntax match qfFileName "^[^: ]*" nextgroup=qfLineCol +syntax match qfLineCol ":\(\d\+:\)\{,2} " contained + +highlight default link qfFileName Directory +highlight default link qfLineCol Delimiter +highlight default link qfError DiagnosticError +highlight default link qfWarn DiagnosticWarn +highlight default link qfInfo DiagnosticInfo +highlight default link qfNote DiagnosticHint +highlight default link qfPassed DiagnosticOk +highlight default link qfFailed DiagnosticError + +highlight clear QuickFixLine +highlight QuickFixLine gui=underline + +let b:current_syntax = "qf"