Skip to content

Commit

Permalink
fix: fix diagnostic for line 1
Browse files Browse the repository at this point in the history
  • Loading branch information
rachartier committed Jul 28, 2024
1 parent b2be9f4 commit 4c4137b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lua/tiny-inline-diagnostic/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ local function apply_diagnostics_virtual_texts(opts, event)
-- group all_diags by lnum
local all_diags_grouped = {}
for _, diag in ipairs(diagnostics) do
if diag.lnum >= fist_visually_seen_line and diag.lnum <= last_visually_seen_line then
if diag.lnum >= fist_visually_seen_line - 1 and diag.lnum <= last_visually_seen_line then
if all_diags_grouped[diag.lnum] == nil then
all_diags_grouped[diag.lnum] = {}
end
table.insert(all_diags_grouped[diag.lnum], diag)
end
end

local cursor_line = vim.api.nvim_win_get_cursor(0)[1] - 1

for lnum, line_diags in pairs(all_diags_grouped) do
if line_diags == nil then
return
Expand All @@ -122,7 +124,6 @@ local function apply_diagnostics_virtual_texts(opts, event)

local virt_priority = opts.options.virt_texts.priority
local virt_lines, offset, need_to_be_under
local cursor_line = vim.api.nvim_win_get_cursor(0)[1] - 1

if opts.options.multiple_diag_under_cursor and lnum == cursor_line then
virt_lines, offset, need_to_be_under =
Expand Down
12 changes: 8 additions & 4 deletions lua/tiny-inline-diagnostic/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ local function get_hi(name)
return {
fg = utils.int_to_hex(hi.fg),
bg = utils.int_to_hex(hi.bg),
italic = hi.italic,
}
end

--- Function to setup highlights for diagnostics.
-- @param blend table - The table of blend options, which includes the blend factor.
-- @param default_hi table - The table of default highlights, which includes the colors for each diagnostic type, the arrow, and the background.
-- @param italics boolean - Whether to use italics for the diagnostics.
function M.setup_highlights(blend, default_hi)
local colors = {
error = get_hi(default_hi.error),
warn = get_hi(default_hi.warn),
info = get_hi(default_hi.info),
hint = get_hi(default_hi.hint),
ok = get_hi(default_hi.ok),
arrow = get_hi(default_hi.arrow),
}

Expand Down Expand Up @@ -52,10 +55,11 @@ function M.setup_highlights(blend, default_hi)
}

local hi = {
TinyInlineDiagnosticVirtualTextError = { bg = blends.error, fg = colors.error.fg },
TinyInlineDiagnosticVirtualTextWarn = { bg = blends.warn, fg = colors.warn.fg },
TinyInlineDiagnosticVirtualTextInfo = { bg = blends.info, fg = colors.info.fg },
TinyInlineDiagnosticVirtualTextHint = { bg = blends.hint, fg = colors.hint.fg },
TinyInlineDiagnosticVirtualTextError = { bg = blends.error, fg = colors.error.fg, italic = colors.error.italic },
TinyInlineDiagnosticVirtualTextWarn = { bg = blends.warn, fg = colors.warn.fg, italic = colors.warn.italic },
TinyInlineDiagnosticVirtualTextInfo = { bg = blends.info, fg = colors.info.fg, italic = colors.info.italic },
TinyInlineDiagnosticVirtualTextHint = { bg = blends.hint, fg = colors.hint.fg, italic = colors.hint.italic },
TinyInlineDiagnosticVirtualTextOk = { bg = blends.hint, fg = colors.hint.fg, italic = colors.ok.italic },

TinyInlineDiagnosticVirtualTextArrow = { bg = colors.background, fg = colors.arrow.fg },

Expand Down

0 comments on commit 4c4137b

Please sign in to comment.