Skip to content

Commit 7a41211

Browse files
committed
feat: add option to set arrow color to diagnostic severity. Fixes #104
1 parent 576351d commit 7a41211

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ require("tiny-inline-diagnostic").setup({
8080
-- Use icons defined in the diagnostic configuration
8181
use_icons_from_diagnostic = false,
8282

83+
-- Set the arrow icon to the same color as the first diagnostic severity
84+
set_arrow_to_diag_color = false,
85+
8386
-- Add messages to diagnostics when multiline diagnostics are enabled
8487
-- If set to false, only signs will be displayed
8588
add_messages = true,

lua/tiny-inline-diagnostic/chunk.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,25 @@ end
181181
---@param opts table: The options table.
182182
---@param diagnostic_line number: The line number of the diagnostic message.
183183
---@param ret table: The return table containing diagnostic information.
184+
---@param hl_diag_hi string: The highlight group for the diagnostic message.
184185
---@return table: A table representing the virtual text array for the arrow.
185-
function M.get_arrow_from_chunk(opts, diagnostic_line, ret)
186+
function M.get_arrow_from_chunk(opts, diagnostic_line, ret, hl_diag_hi)
186187
local arrow = opts.signs.arrow
187188
local need_to_be_under = ret.need_to_be_under
188189

189190
local chunk = {}
191+
190192
local hi = "TinyInlineDiagnosticVirtualTextArrow"
193+
if opts.options.set_arrow_to_diag_color then
194+
hi = hl_diag_hi .. "CursorLine"
195+
end
191196

192197
if diagnostic_line ~= ret.line or ret.need_to_be_under then
193198
hi = "TinyInlineDiagnosticVirtualTextArrowNoBg"
199+
200+
if opts.options.set_arrow_to_diag_color then
201+
hi = hl_diag_hi .. "NoBg"
202+
end
194203
end
195204

196205
if need_to_be_under then

lua/tiny-inline-diagnostic/highlights.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ local function create_highlight_groups(colors, blends, transparent)
9696
italic = colors[string.lower(name)].italic,
9797
}
9898

99+
hi[HIGHLIGHT_PREFIX .. name .. "NoBg"] = {
100+
fg = colors[string.lower(name)].fg,
101+
bg = "None",
102+
italic = colors[string.lower(name)].italic,
103+
}
104+
99105
-- Inverse highlights with and without background
100106
hi[INV_HIGHLIGHT_PREFIX .. name] = {
101107
fg = blends[string.lower(name)],

lua/tiny-inline-diagnostic/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ local default_config = {
2525
options = {
2626
show_source = false,
2727
add_messages = true,
28+
set_arrow_to_diag_color = true,
2829
use_icons_from_diagnostic = false,
2930
throttle = 20,
3031
softwrap = 30,

lua/tiny-inline-diagnostic/virtual_text.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ local function build_first_chunk(opts, chunk_info, message, hl, index_diag, tota
4949

5050
if index_diag == 1 then
5151
local cursor_line = vim.api.nvim_win_get_cursor(0)[1] - 1
52-
local chunk_arrow = chunk_utils.get_arrow_from_chunk(opts, cursor_line, chunk_info)
52+
local chunk_arrow = chunk_utils.get_arrow_from_chunk(opts, cursor_line, chunk_info, hl.diag_hi)
5353

5454
if type(chunk_arrow[1]) == "table" then
5555
return { chunk_arrow, chunk_header }

0 commit comments

Comments
 (0)