Skip to content

Commit fe42ac1

Browse files
committed
fix: fix background on cursorline, better perf
1 parent bcb5646 commit fe42ac1

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ require('tiny-inline-diagnostic').setup({
6161
factor = 0.27,
6262
},
6363
options = {
64-
clear_on_insert = false,
6564
--- When overflow="wrap", when the message is too long, it is then displayed on multiple lines.
6665
overflow = "wrap",
6766

lua/tiny-inline-diagnostic/diagnostic.lua

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ local M = {}
33
local diagnostic_ns = vim.api.nvim_create_namespace("CursorDiagnostics")
44
local utis = require("tiny-inline-diagnostic.utils")
55

6+
local previous_line_number = 0
7+
68
--- Function to get diagnostics for the current position in the code.
79
-- @param diagnostics table - The table of diagnostics to check.
810
-- @param curline number - The current line number.
@@ -154,17 +156,30 @@ end
154156
function M.set_diagnostic_autocmds(opts)
155157
vim.api.nvim_create_autocmd("LspAttach", {
156158
callback = function(event)
157-
if opts.options.clear_on_insert then
158-
vim.api.nvim_create_autocmd("InsertEnter", {
159-
buffer = event.buf,
160-
callback = function()
161-
vim.api.nvim_buf_clear_namespace(event.buf, diagnostic_ns, 0, -1)
162-
end,
163-
desc = "Clear diagnostics on insert enter",
164-
})
165-
end
159+
-- if opts.options.clear_on_insert then
160+
-- vim.api.nvim_create_autocmd("InsertEnter", {
161+
-- buffer = event.buf,
162+
-- callback = function()
163+
-- pcall(vim.api.nvim_buf_clear_namespace, event.buf, diagnostic_ns, 0, -1)
164+
-- end,
165+
-- desc = "Clear diagnostics on insert enter",
166+
-- })
167+
-- end
168+
--
169+
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
170+
buffer = event.buf,
171+
callback = function()
172+
local cursor_pos = vim.api.nvim_win_get_cursor(0)
173+
local curline = cursor_pos[1] - 1
174+
175+
if curline == previous_line_number then
176+
return
177+
end
178+
pcall(vim.api.nvim_buf_clear_namespace, event.buf, diagnostic_ns, 0, -1)
179+
end
180+
})
166181

167-
vim.api.nvim_create_autocmd({ "CursorHold", "VimResized", "CursorMovedI" }, {
182+
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI", "VimResized" }, {
168183
buffer = event.buf,
169184
callback = function()
170185
pcall(vim.api.nvim_buf_clear_namespace, event.buf, diagnostic_ns, 0, -1)
@@ -175,6 +190,7 @@ function M.set_diagnostic_autocmds(opts)
175190
return
176191
end
177192

193+
previous_line_number = curline
178194
local virt_texts = forge_virt_texts_from_diagnostic(opts, diag[1])
179195

180196
local virt_lines = {}

lua/tiny-inline-diagnostic/highlights.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ function M.setup_highlights(blend, default_hi)
2424
info = get_hi(default_hi.info),
2525
hint = get_hi(default_hi.hint),
2626
arrow = get_hi(default_hi.arrow),
27-
background = default_hi.background,
2827
}
2928

29+
if default_hi.background:sub(1, 1) == "#" then
30+
colors.background = default_hi.background
31+
else
32+
colors.background = get_hi(default_hi.background).bg
33+
end
34+
3035
local factor = blend.factor
3136
local c = colors.background
3237

@@ -42,12 +47,12 @@ function M.setup_highlights(blend, default_hi)
4247
TinyInlineDiagnosticVirtualTextWarn = { bg = blends.warn, fg = colors.warn.fg },
4348
TinyInlineDiagnosticVirtualTextInfo = { bg = blends.info, fg = colors.info.fg },
4449
TinyInlineDiagnosticVirtualTextHint = { bg = blends.hint, fg = colors.hint.fg },
45-
TinyInlineDiagnosticVirtualTextArrow = colors.arrow,
50+
TinyInlineDiagnosticVirtualTextArrow = { bg = colors.background, colors.arrow },
4651

47-
TinyInlineInvDiagnosticVirtualTextError = { fg = blends.error, bg = "None" },
48-
TinyInlineInvDiagnosticVirtualTextWarn = { fg = blends.warn, bg = "None" },
49-
TinyInlineInvDiagnosticVirtualTextInfo = { fg = blends.info, bg = "None" },
50-
TinyInlineInvDiagnosticVirtualTextHint = { fg = blends.hint, bg = "None" },
52+
TinyInlineInvDiagnosticVirtualTextError = { fg = blends.error, bg = colors.background },
53+
TinyInlineInvDiagnosticVirtualTextWarn = { fg = blends.warn, bg = colors.background },
54+
TinyInlineInvDiagnosticVirtualTextInfo = { fg = blends.info, bg = colors.background },
55+
TinyInlineInvDiagnosticVirtualTextHint = { fg = blends.hint, bg = colors.background },
5156
}
5257

5358
for name, opts in pairs(hi) do

lua/tiny-inline-diagnostic/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ local default_config = {
1717
info = "DiagnosticInfo",
1818
hint = "DiagnosticHint",
1919
arrow = "NonText",
20-
background = "None",
20+
background = "CursorLine",
2121
},
2222
blend = {
2323
factor = 0.27,
2424
},
2525
options = {
26-
clear_on_insert = false,
26+
-- clear_on_insert = false,
2727
overflow = "wrap",
2828
break_line = {
2929
enabled = false,

0 commit comments

Comments
 (0)