diff .chezmoitemplates/init.lua @ 616:08bb1c92e5e5

Add cleaner quickfix
author zegervdv <zegervdv@me.com>
date Sun, 24 Jul 2022 14:48:01 +0200
parents 0cace1b99e77
children d130c5c8b4e9
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