Skip to content

Commit 963f17d

Browse files
committed
refactor(nvim): diagnostic virtual_text toggle and current_line
Move keybind to toggle virtual_text config properly. Use current_line ability if available. Signed-off-by: Tom Saeger <tom.saeger@gmail.com>
1 parent 497d30c commit 963f17d

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lua/core/keymaps.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ vim.keymap.set(
109109
)
110110
vim.keymap.set('n', 'gl', vim.diagnostic.open_float, { desc = '[D]iagnostic [O]pen floating message' })
111111
vim.keymap.set('n', '<leader>dl', vim.diagnostic.setloclist, { desc = '[D]iagnostic [l]ocation list open' })
112-
vim.keymap.set('n', '<leader>dv', function()
113-
vim.diagnostic.config { virtual_text = not vim.diagnostic.config().virtual_text }
114-
end, { desc = '[D]iagnostic [v]irtual_text toggle' })
115112

116113
-- Dashboard
117114
vim.keymap.set('n', '<leader>;', function()

lua/core/snippets.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
-- https://github.com/NvChad/NvChad/issues/1907
55
(vim.hl or vim.highlight).priorities.semantic_tokens = 95 -- Or any number lower than 100, treesitter's priority level
66

7+
local virtual_text = {
8+
prefix = '',
9+
-- Add a custom format function to show error codes
10+
format = function(diagnostic)
11+
local code = diagnostic.code and string.format('[%s]', diagnostic.code) or ''
12+
return string.format('%s %s', code, diagnostic.message)
13+
end,
14+
}
15+
-- only show current line's diagnostic
16+
if vim.version.ge(vim.version.parse(tostring(vim.version())), { 0, 11, 0 }) then
17+
virtual_text.current_line = true
18+
end
19+
720
-- Appearance of diagnostics
821
vim.diagnostic.config {
9-
virtual_text = {
10-
prefix = '',
11-
-- Add a custom format function to show error codes
12-
format = function(diagnostic)
13-
local code = diagnostic.code and string.format('[%s]', diagnostic.code) or ''
14-
return string.format('%s %s', code, diagnostic.message)
15-
end,
16-
},
22+
virtual_text = virtual_text,
1723
underline = false,
1824
update_in_insert = true,
1925
float = {
@@ -24,6 +30,13 @@ vim.diagnostic.config {
2430
vim.cmd 'highlight DiagnosticVirtualText guibg=NONE'
2531
end,
2632
}
33+
vim.keymap.set('n', '<leader>dv', function()
34+
if vim.diagnostic.config().virtual_text then
35+
vim.diagnostic.config { virtual_text = false }
36+
else
37+
vim.diagnostic.config { virtual_text = virtual_text }
38+
end
39+
end, { desc = '[D]iagnostic [v]irtual_text toggle' })
2740

2841
-- Highlight on yank
2942
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })

0 commit comments

Comments
 (0)