all repos — dotfiles @ 3a0d9ecef1acfc03e241e62bd8da99bd3365162f

my *nix dotfiles

nvim: add diagnostic counts to statusline
Anirudh Oppiliappan x@icyphox.sh
Tue, 04 Jun 2024 11:51:57 +0300
commit

3a0d9ecef1acfc03e241e62bd8da99bd3365162f

parent

bf8fe9b1131f356961fa0f16227a247dce7252a4

2 files changed, 45 insertions(+), 20 deletions(-)

jump to
M nvim/colors/plain.luanvim/colors/plain.lua

@@ -138,7 +138,7 @@ VertSplit = { fg = border },

WinSeparator = { fg = border }, Visual = { bg = light_grey }, WarningMsg = { fg = dark_yellow, bold = true }, - Whitespace = { fg = border }, + Whitespace = { fg = light_grey }, WildMenu = { link = 'PmenuSel' }, -- ALE ALEError = { fg = red, bold = true },

@@ -252,10 +252,10 @@ DiagnosticFloatingError = { fg = red, bold = true },

DiagnosticFloatingHint = { fg = black, bold = true }, DiagnosticFloatingInfo = { fg = blue, bold = true }, DiagnosticFloatingWarn = { fg = dark_yellow, bold = true }, - DiagnosticError = { fg = red, bold = true }, - DiagnosticHint = { fg = grey, bold = true }, - DiagnosticInfo = { fg = blue, bold = true }, - DiagnosticWarn = { fg = dark_yellow, bold = true }, + DiagnosticError = { fg = red }, + DiagnosticHint = { fg = grey }, + DiagnosticInfo = { fg = blue }, + DiagnosticWarn = { fg = dark_yellow }, -- Make makeTarget = { link = 'Function' }, -- Markdown

@@ -441,6 +441,14 @@ yardTypeList = { link = 'Todo' },

-- custom highlight groups ['@variable'] = { fg = black }, + + -- statusline + LinePrimaryBlock = { fg = black, bg = background }, + LineSecondaryBlock = { fg = blue, bg = background }, + LineError = { link = 'DiagnosticError' }, + LineHint = { link = 'DiagnosticHint' }, + LineInfo = { link = 'DiagnosticInfo' }, + LineWarning = { link = 'DiagnosticWarn' }, } for group, opts in pairs(highlights) do
M nvim/lua/statusline/line.luanvim/lua/statusline/line.lua

@@ -1,15 +1,28 @@

local git = require('statusline.git') +local vd = require('vim.diagnostic') local M = {} --- set highlights for statusline sections -vim.api.nvim_exec( -[[ - hi PrimaryBlock ctermfg=06 ctermbg=00 - hi SecondaryBlock ctermfg=07 ctermbg=00 - hi Blanks ctermfg=08 ctermbg=00 - hi GitClean ctermfg=02 ctermbg=00 - hi GitDirty ctermfg=01 ctermbg=00 -]], false) +local function diagnostic_highlight(diagnostics) + local severity = { + E = diagnostics[vd.severity.E], + W = diagnostics[vd.severity.W], + I = diagnostics[vd.severity.I], + H = diagnostics[vd.severity.N], + } + local highlight = { + E = '%#LineError#', + W = '%#LineWarning#', + I = '%#LineInfo#', + H = '%#LineHint#', + } + local stl = {} + for k, v in pairs(severity) do + if v > 0 then + table.insert(stl, ' '..highlight[k]..k..v) + end + end + return table.concat(stl) +end function M.statusline() local stl = {}

@@ -17,17 +30,21 @@ if vim.bo.filetype ~= 'NvimTree' then

stl = {''} end + local diagnostics = vd.count(0) + stl = { - '%#PrimaryBlock#', + '%#LinePrimaryBlock#', '%f', - '%#Blanks#', + '%#LineBlanks#', '%m', - '%#SecondaryBlock#', - ' '..git.git_branch, + --'%#LineSecondaryBlock#', + --' '..git.git_branch, '%=', - '%#SecondaryBlock#', + diagnostic_highlight(diagnostics)..' ', + '%#LineBlanks#', + '%#LineSecondaryBlock#', '%l,%c ', - '%#PrimaryBlock#', + '%#LinePrimaryBlock#', '%{&filetype}', } return table.concat(stl)