Skip to content

Commit c88e6fe

Browse files
committed
fix(highlights)!: improve handling of cursorline background
1 parent 1477762 commit c88e6fe

5 files changed

Lines changed: 40 additions & 25 deletions

File tree

.beads/issues.jsonl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"id":"tiny-inline-diagnostic.nvim-ciu","content_hash":"b1bae68097b016c449d1eaf521de63eafc097bec5eb78663fcdee27199adb1e8","title":"Run test suite validation","description":"Execute full test suite to verify 187 tests still pass after refactoring","status":"open","priority":1,"issue_type":"task","created_at":"2025-11-09T11:10:39.334213939+01:00","updated_at":"2025-11-09T11:10:39.334213939+01:00","source_repo":"."}
2+
{"id":"tiny-inline-diagnostic.nvim-kxl","content_hash":"43d7069fb55ce9a9b2063a45053dc895db5773821716a45b3d4247b2d9e9c0c3","title":"Refactor chunk.lua to facade pattern","description":"Transform chunk.lua to re-export functions from new submodules while maintaining API compatibility","status":"in_progress","priority":1,"issue_type":"task","created_at":"2025-11-09T11:10:38.252467341+01:00","updated_at":"2025-11-09T11:10:43.080627553+01:00","source_repo":"."}
3+
{"id":"tiny-inline-diagnostic.nvim-vpy","content_hash":"ad527f313f04f728beb5b3858cd83bd4d529175dace46bf3ed6f901c6a16c08e","title":"Analyze issue #158: diagnostics not showing with basedpyright","description":"Investigate why tiny-inline-diagnostic.nvim shows for nixd but not basedpyright. Review setup order, event triggers, buffer attach logic, diagnostic fields.","status":"in_progress","priority":2,"issue_type":"task","created_at":"2025-11-22T16:50:20.70267504+01:00","updated_at":"2025-11-22T16:50:22.407223959+01:00","source_repo":"."}

lua/tiny-inline-diagnostic/chunk.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,13 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
435435

436436
local other_extmarks_offset = extmarks.handle_other_extmarks(buf, diag_line, line_length)
437437

438-
local multilines_enabled = type(opts.options.multilines) == "table" and opts.options.multilines.enabled
438+
local multilines_enabled = type(opts.options.multilines) == "table"
439+
and opts.options.multilines.enabled
439440
or opts.options.multilines
440441

441-
if (opts.options.overflow.mode ~= "none" and not multilines_enabled) or cursor_line == diag_line then
442+
if
443+
(opts.options.overflow.mode ~= "none" and not multilines_enabled) or cursor_line == diag_line
444+
then
442445
local line_display_width = lines[1] and vim.fn.strdisplaywidth(lines[1]) or 0
443446
local visual_line_width = line_display_width + other_extmarks_offset
444447

lua/tiny-inline-diagnostic/highlighter_builder.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ function M.build_base_groups(colors, blends, transparent)
4141
italic = color.italic,
4242
}
4343

44+
hi[INV_HIGHLIGHT_PREFIX .. name .. "CursorLine"] = {
45+
fg = blends[name_lower],
46+
bg = colors.cursor_line.bg,
47+
italic = color.italic,
48+
}
49+
4450
hi[INV_HIGHLIGHT_PREFIX .. name .. "NoBg"] = {
4551
fg = blends[name_lower],
4652
bg = "None",
@@ -49,7 +55,7 @@ function M.build_base_groups(colors, blends, transparent)
4955
end
5056

5157
hi[HIGHLIGHT_PREFIX .. "Arrow"] = {
52-
bg = colors.background,
58+
bg = colors.cursor_line.bg,
5359
fg = colors.arrow.fg,
5460
}
5561
hi[HIGHLIGHT_PREFIX .. "ArrowNoBg"] = {

lua/tiny-inline-diagnostic/highlights.lua

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,32 @@ end
7474

7575
---@param blend BlendOptions
7676
---@param default_hi DefaultHighlights
77-
function M.setup_highlights(blend, default_hi, transparent_bg, transparent_cursorline)
78-
-- Get base colors
77+
function M.setup_highlights(blend, default_hi, transparent_bg)
78+
if not transparent_bg then
79+
transparent_bg = false
80+
end
81+
82+
if blend.factor == 0 then
83+
transparent_bg = true
84+
end
85+
86+
local cursorline_hl = get_highlight("CursorLine")
87+
local is_cursorline_enabled = vim.opt.cursorline:get()
88+
local has_cursorline_bg = cursorline_hl.bg ~= "None"
89+
90+
local cursor_line_color = (is_cursorline_enabled and has_cursorline_bg) and cursorline_hl
91+
or { bg = "None" }
92+
7993
local colors = {
8094
error = get_highlight(default_hi.error),
8195
warn = get_highlight(default_hi.warn),
8296
info = get_highlight(default_hi.info),
8397
hint = get_highlight(default_hi.hint),
8498
ok = get_highlight(default_hi.ok),
8599
arrow = get_highlight(default_hi.arrow),
86-
cursor_line = transparent_cursorline and { bg = "None" } or get_highlight("CursorLine"),
100+
cursor_line = cursor_line_color,
87101
}
88102

89-
if not transparent_bg then
90-
transparent_bg = false
91-
end
92-
93-
if blend.factor == 0 then
94-
transparent_bg = true
95-
end
96-
97103
-- Get special colors
98104
colors.background = get_background_color(default_hi.background)
99105
colors.mixing_color = get_mixing_color(default_hi.mixing_color)
@@ -127,8 +133,11 @@ end
127133
function M.get_diagnostic_highlights(blend_factor, diag_ret, curline, index_diag)
128134
local diag_hi, diag_inv_hi, body_hi = M.get_diagnostic_highlights_from_severity(diag_ret.severity)
129135

130-
if (diag_ret.line and diag_ret.line == curline) and index_diag == 1 and blend_factor == 0 then
131-
diag_hi = diag_hi .. "CursorLine"
136+
if (diag_ret.line and diag_ret.line == curline) and index_diag == 1 then
137+
if blend_factor == 0 then
138+
diag_hi = diag_hi .. "CursorLine"
139+
end
140+
diag_inv_hi = diag_inv_hi .. "CursorLine"
132141
end
133142

134143
if

lua/tiny-inline-diagnostic/init.lua

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ local presets = require("tiny-inline-diagnostic.presets")
1313
local default_config = {
1414
preset = "modern",
1515
transparent_bg = false,
16-
transparent_cursorline = true,
1716
hi = {
1817
error = "DiagnosticError",
1918
warn = "DiagnosticWarn",
@@ -84,12 +83,7 @@ local function setup_colorscheme_handler(config)
8483
vim.api.nvim_create_autocmd("ColorScheme", {
8584
pattern = "*",
8685
callback = function()
87-
hi.setup_highlights(
88-
config.blend,
89-
config.hi,
90-
config.transparent_bg,
91-
config.transparent_cursorline
92-
)
86+
hi.setup_highlights(config.blend, config.hi, config.transparent_bg)
9387
end,
9488
})
9589
end
@@ -137,7 +131,7 @@ function M.setup(opts)
137131

138132
M.config = config
139133

140-
hi.setup_highlights(config.blend, config.hi, config.transparent_bg, config.transparent_cursorline)
134+
hi.setup_highlights(config.blend, config.hi, config.transparent_bg)
141135

142136
setup_colorscheme_handler(config)
143137
diag.set_diagnostic_autocmds(config)
@@ -157,7 +151,7 @@ function M.change(blend, highlights)
157151
hi = highlights or M.config.hi,
158152
})
159153

160-
hi.setup_highlights(config.blend, config.hi, config.transparent_bg, config.transparent_cursorline)
154+
hi.setup_highlights(config.blend, config.hi, config.transparent_bg)
161155
end
162156

163157
--- Enable the diagnostic display.

0 commit comments

Comments
 (0)