Skip to content

Commit 5ab96be

Browse files
committed
feat(recipes): add diagnostic-virtual-lines-current-line recipe
1 parent cdac788 commit 5ab96be

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# AstroCore - Automatically virtual lines on current line only
2+
3+
**Website:** <https://docs.astronvim.com/recipes/diagnostics/#virtual-line-current-line-only>
4+
5+
This plugin specification configures AstroCore to show virtual text except on the current line which shows as virtual lines.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
local og_virt_text
2+
local og_virt_line
3+
return {
4+
"AstroNvim/astrocore",
5+
---@type AstroCoreOpts
6+
opts = {
7+
features = {
8+
diagnostics = true,
9+
},
10+
diagnostics = {
11+
virtual_text = true,
12+
virtual_lines = { current_line = true },
13+
underline = true,
14+
update_in_insert = false,
15+
},
16+
autocmds = {
17+
diagnostic_only_virtlines = {
18+
{
19+
event = { "CursorMoved", "DiagnosticChanged" },
20+
callback = function()
21+
if og_virt_line == nil then og_virt_line = vim.diagnostic.config().virtual_lines end
22+
23+
-- ignore if virtual_lines.current_line is disabled
24+
if not (og_virt_line and og_virt_line.current_line) then
25+
if og_virt_text then
26+
vim.diagnostic.config { virtual_text = og_virt_text }
27+
og_virt_text = nil
28+
end
29+
return
30+
end
31+
32+
if og_virt_text == nil then og_virt_text = vim.diagnostic.config().virtual_text end
33+
34+
local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
35+
36+
if vim.tbl_isempty(vim.diagnostic.get(0, { lnum = lnum })) then
37+
vim.diagnostic.config { virtual_text = og_virt_text }
38+
else
39+
vim.diagnostic.config { virtual_text = false }
40+
end
41+
end,
42+
},
43+
{
44+
event = "ModeChanged",
45+
callback = function() pcall(vim.diagnostic.show) end,
46+
},
47+
},
48+
},
49+
},
50+
}

0 commit comments

Comments
 (0)