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