From abe21bf84aa57604eb8fa4183ba1c71c6a33460f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20CHARTIER?= Date: Sat, 13 Jul 2024 02:37:50 +0200 Subject: [PATCH] feat: improve arrow for under diagnostic --- lua/tiny-inline-diagnostic/diagnostic.lua | 20 +++++++++++++++++--- lua/tiny-inline-diagnostic/init.lua | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lua/tiny-inline-diagnostic/diagnostic.lua b/lua/tiny-inline-diagnostic/diagnostic.lua index 68511e7..d10bece 100644 --- a/lua/tiny-inline-diagnostic/diagnostic.lua +++ b/lua/tiny-inline-diagnostic/diagnostic.lua @@ -142,7 +142,6 @@ local function get_arrow_from_chunk( if need_to_be_under then arrow = opts.signs.up_arrow - arrow = string.rep(" ", cursorpos[2] - math.floor(#arrow / 2) + 1) .. arrow chunck = { { " ", "None" }, { arrow, "TinyInlineDiagnosticVirtualTextArrow" }, @@ -223,7 +222,6 @@ local function forge_virt_texts_from_diagnostic(opts, cursorpos, index_diag, dia need_to_be_under ) - if type(chunck_arrow[1]) == "table" then table.insert(all_virtual_texts, chunck_arrow) else @@ -353,13 +351,28 @@ local function apply_diagnostics_virtual_texts(opts, event) ) end - local win_col = vim.fn.virtcol("$") if need_to_be_under then win_col = 0 end + if need_to_be_under then + vim.api.nvim_buf_set_extmark(event.buf, diagnostic_ns, curline + 1, cursorpos[2], { + id = curline + 100, + line_hl_group = "CursorLine", + virt_text_pos = "overlay", + virt_text_win_col = cursorpos[2] - 1, + virt_text = virt_lines[2], + priority = virt_prorioty, + strict = false, + }) + table.remove(virt_lines, 2) + if not diag_overflow_last_line then + curline = curline + 1 + end + end + if diag_overflow_last_line then local other_virt_lines = {} for i, line in ipairs(virt_lines) do @@ -368,6 +381,7 @@ local function apply_diagnostics_virtual_texts(opts, event) table.insert(other_virt_lines, line) end end + vim.api.nvim_buf_set_extmark(event.buf, diagnostic_ns, curline, 0, { id = curline + 1, line_hl_group = "CursorLine", diff --git a/lua/tiny-inline-diagnostic/init.lua b/lua/tiny-inline-diagnostic/init.lua index d041426..8437c38 100644 --- a/lua/tiny-inline-diagnostic/init.lua +++ b/lua/tiny-inline-diagnostic/init.lua @@ -9,7 +9,7 @@ local default_config = { right = "", diag = " ●", arrow = "  ", - up_arrow = "  ", + up_arrow = "", vertical = " │", vertical_end = " └" },