tangled
alpha
login
or
join now
anirudh.fi
/
dotfiles
5
fork
atom
my nix dotfiles
5
fork
atom
overview
issues
pulls
pipelines
nvim: add diagnostic counts to statusline
anirudh.fi
2 years ago
3a0d9ece
bf8fe9b1
+45
-20
2 changed files
expand all
collapse all
unified
split
nvim
colors
plain.lua
lua
statusline
line.lua
+13
-5
nvim/colors/plain.lua
···
138
WinSeparator = { fg = border },
139
Visual = { bg = light_grey },
140
WarningMsg = { fg = dark_yellow, bold = true },
141
-
Whitespace = { fg = border },
142
WildMenu = { link = 'PmenuSel' },
143
-- ALE
144
ALEError = { fg = red, bold = true },
···
252
DiagnosticFloatingHint = { fg = black, bold = true },
253
DiagnosticFloatingInfo = { fg = blue, bold = true },
254
DiagnosticFloatingWarn = { fg = dark_yellow, bold = true },
255
-
DiagnosticError = { fg = red, bold = true },
256
-
DiagnosticHint = { fg = grey, bold = true },
257
-
DiagnosticInfo = { fg = blue, bold = true },
258
-
DiagnosticWarn = { fg = dark_yellow, bold = true },
259
-- Make
260
makeTarget = { link = 'Function' },
261
-- Markdown
···
441
442
-- custom highlight groups
443
['@variable'] = { fg = black },
0
0
0
0
0
0
0
0
444
}
445
446
for group, opts in pairs(highlights) do
···
138
WinSeparator = { fg = border },
139
Visual = { bg = light_grey },
140
WarningMsg = { fg = dark_yellow, bold = true },
141
+
Whitespace = { fg = light_grey },
142
WildMenu = { link = 'PmenuSel' },
143
-- ALE
144
ALEError = { fg = red, bold = true },
···
252
DiagnosticFloatingHint = { fg = black, bold = true },
253
DiagnosticFloatingInfo = { fg = blue, bold = true },
254
DiagnosticFloatingWarn = { fg = dark_yellow, bold = true },
255
+
DiagnosticError = { fg = red },
256
+
DiagnosticHint = { fg = grey },
257
+
DiagnosticInfo = { fg = blue },
258
+
DiagnosticWarn = { fg = dark_yellow },
259
-- Make
260
makeTarget = { link = 'Function' },
261
-- Markdown
···
441
442
-- custom highlight groups
443
['@variable'] = { fg = black },
444
+
445
+
-- statusline
446
+
LinePrimaryBlock = { fg = black, bg = background },
447
+
LineSecondaryBlock = { fg = blue, bg = background },
448
+
LineError = { link = 'DiagnosticError' },
449
+
LineHint = { link = 'DiagnosticHint' },
450
+
LineInfo = { link = 'DiagnosticInfo' },
451
+
LineWarning = { link = 'DiagnosticWarn' },
452
}
453
454
for group, opts in pairs(highlights) do
+32
-15
nvim/lua/statusline/line.lua
···
1
local git = require('statusline.git')
0
2
local M = {}
3
4
-
-- set highlights for statusline sections
5
-
vim.api.nvim_exec(
6
-
[[
7
-
hi PrimaryBlock ctermfg=06 ctermbg=00
8
-
hi SecondaryBlock ctermfg=07 ctermbg=00
9
-
hi Blanks ctermfg=08 ctermbg=00
10
-
hi GitClean ctermfg=02 ctermbg=00
11
-
hi GitDirty ctermfg=01 ctermbg=00
12
-
]], false)
0
0
0
0
0
0
0
0
0
0
0
0
13
14
function M.statusline()
15
local stl = {}
···
17
stl = {''}
18
end
19
0
0
20
stl = {
21
-
'%#PrimaryBlock#',
22
'%f',
23
-
'%#Blanks#',
24
'%m',
25
-
'%#SecondaryBlock#',
26
-
' '..git.git_branch,
27
'%=',
28
-
'%#SecondaryBlock#',
0
0
29
'%l,%c ',
30
-
'%#PrimaryBlock#',
31
'%{&filetype}',
32
}
33
return table.concat(stl)
···
1
local git = require('statusline.git')
2
+
local vd = require('vim.diagnostic')
3
local M = {}
4
5
+
local function diagnostic_highlight(diagnostics)
6
+
local severity = {
7
+
E = diagnostics[vd.severity.E],
8
+
W = diagnostics[vd.severity.W],
9
+
I = diagnostics[vd.severity.I],
10
+
H = diagnostics[vd.severity.N],
11
+
}
12
+
local highlight = {
13
+
E = '%#LineError#',
14
+
W = '%#LineWarning#',
15
+
I = '%#LineInfo#',
16
+
H = '%#LineHint#',
17
+
}
18
+
local stl = {}
19
+
for k, v in pairs(severity) do
20
+
if v > 0 then
21
+
table.insert(stl, ' '..highlight[k]..k..v)
22
+
end
23
+
end
24
+
return table.concat(stl)
25
+
end
26
27
function M.statusline()
28
local stl = {}
···
30
stl = {''}
31
end
32
33
+
local diagnostics = vd.count(0)
34
+
35
stl = {
36
+
'%#LinePrimaryBlock#',
37
'%f',
38
+
'%#LineBlanks#',
39
'%m',
40
+
--'%#LineSecondaryBlock#',
41
+
--' '..git.git_branch,
42
'%=',
43
+
diagnostic_highlight(diagnostics)..' ',
44
+
'%#LineBlanks#',
45
+
'%#LineSecondaryBlock#',
46
'%l,%c ',
47
+
'%#LinePrimaryBlock#',
48
'%{&filetype}',
49
}
50
return table.concat(stl)