Mercurial > dotfiles
changeset 616:08bb1c92e5e5
Add cleaner quickfix
author | zegervdv <zegervdv@me.com> |
---|---|
date | Sun, 24 Jul 2022 14:48:01 +0200 |
parents | 0cace1b99e77 |
children | d130c5c8b4e9 |
files | .chezmoitemplates/init.lua dot_config/nvim/syntax/qf.vim |
diffstat | 2 files changed, 69 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/.chezmoitemplates/init.lua Mon Jul 25 14:18:02 2022 +0200 +++ b/.chezmoitemplates/init.lua Sun Jul 24 14:48:01 2022 +0200 @@ -530,7 +530,7 @@ hl = { fg = 'diag_warn' }, on_click = { callback = function() - vim.diagnostic.setqflist { severity = vim.diagnostic.severity.WARN } + vim.diagnostic.setqflist { severity = { min = vim.diagnostic.severity.WARN } } vim.cmd.copen { mods = { split = 'botright' } } end, name = 'heirline_diagnostics', @@ -756,7 +756,7 @@ c = true, -- Commandline mode } -opt.fillchars = { +opt.fillchars:append { diff = '╱', } @@ -768,6 +768,50 @@ [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) . ' (' . (v:foldend - v:foldstart + 1) . ' lines)']] opt.foldenable = false +function _G.qftf(info) + local items + local ret = {} + if info.quickfix == 1 then + items = fn.getqflist({ id = info.id, items = 0 }).items + else + items = fn.getloclist(info.winid, { id = info.id, items = 0 }).items + end + local limit = 31 + local fnameFmt1, fnameFmt2 = '%-' .. limit .. 's', '…%.' .. (limit - 1) .. 's' + local validFmt = '%s │%5d:%-3d│%s %s' + for i = info.start_idx, info.end_idx do + local e = items[i] + local fname = '' + local str + if e.valid == 1 then + if e.bufnr > 0 then + fname = fn.bufname(e.bufnr) + if fname == '' then + fname = '[No Name]' + else + fname = fname:gsub('^' .. vim.env.HOME, '~') + end + -- char in fname may occur more than 1 width, ignore this issue in order to keep performance + if #fname <= limit then + fname = fnameFmt1:format(fname) + else + fname = fnameFmt2:format(fname:sub(1 - limit)) + end + end + local lnum = e.lnum > 99999 and -1 or e.lnum + local col = e.col > 999 and -1 or e.col + local qtype = e.type == '' and '' or ' ' .. e.type:sub(1, 1):upper() + str = validFmt:format(fname, lnum, col, qtype, e.text) + else + str = e.text + end + table.insert(ret, str) + end + return ret +end + +vim.o.qftf = '{info -> v:lua._G.qftf(info)}' + -- Clean up terminal codes from strings local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dot_config/nvim/syntax/qf.vim Sun Jul 24 14:48:01 2022 +0200 @@ -0,0 +1,23 @@ +if exists('b:current_syntax') + finish +endif + +syn match qfFileName /^[^│]*/ nextgroup=qfSeparatorLeft +syn match qfSeparatorLeft /│/ contained nextgroup=qfLineNr +syn match qfLineNr /[^│]*/ contained nextgroup=qfSeparatorRight +syn match qfSeparatorRight '│' contained nextgroup=qfError,qfWarning,qfInfo,qfNote +syn match qfError / E .*$/ contained +syn match qfWarning / W .*$/ contained +syn match qfInfo / I .*$/ contained +syn match qfNote / [NH] .*$/ contained + +hi def link qfFileName Directory +hi def link qfSeparatorLeft Delimiter +hi def link qfSeparatorRight Delimiter +hi def link qfLineNr LineNr +hi def link qfError DiagnosticSignError +hi def link qfWarning DiagnosticSignWarn +hi def link qfInfo DiagnosticSignInfo +hi def link qfNote DiagnosticSignNote + +let b:current_syntax = 'qf'