Skip to content

Commit

Permalink
fix: fix various issues when under line
Browse files Browse the repository at this point in the history
  • Loading branch information
rachartier committed Jul 13, 2024
1 parent 06d4249 commit 23aca46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
15 changes: 6 additions & 9 deletions lua/tiny-inline-diagnostic/chunck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ end
--- @param line_length number: The length of the line where the diagnostic message is.
--- @param win_width number: The width of the window where the diagnostic message is displayed.
--- @param opts table: The options table, which includes signs for the diagnostic message and the softwrap option.
--- @return table, boolean: A table representing the chunks of the diagnostic message, and a boolean indicating whether the message needs to be displayed under the line.
--- @return table: A table representing the chunks of the diagnostic message.
function M.get_message_chunks_for_overflow(
message,
offset,
Expand All @@ -155,22 +155,21 @@ function M.get_message_chunks_for_overflow(
local distance = win_width - offset - signs_total_text_len

if distance < opts.options.softwrap then
need_to_be_under = true
distance = win_width - signs_total_text_len
end

local message_chunk = {}
message_chunk = utils.wrap_text(message, distance)

return message_chunk, need_to_be_under
return message_chunk
end

function M.get_chunks(opts, diag, plugin_offset, curline, buf)
local win_width = vim.api.nvim_win_get_width(0)
local line_length = #vim.api.nvim_get_current_line()
local offset = 0
local need_to_be_under = false
local win_option_wrap_enabled = vim.api.nvim_get_option_value("wrap", { win = 0 })
-- local win_option_wrap_enabled = vim.api.nvim_get_option_value("wrap", { win = 0 })

local chunks = { diag.message }

Expand All @@ -181,10 +180,8 @@ function M.get_chunks(opts, diag, plugin_offset, curline, buf)
line_length
)

if win_option_wrap_enabled then
if line_length > win_width - opts.options.softwrap then
need_to_be_under = true
end
if line_length > win_width - opts.options.softwrap then
need_to_be_under = true
end

if opts.options.break_line.enabled == true then
Expand All @@ -197,7 +194,7 @@ function M.get_chunks(opts, diag, plugin_offset, curline, buf)
offset = line_length
end

chunks, need_to_be_under = M.get_message_chunks_for_overflow(
chunks = M.get_message_chunks_for_overflow(
diag.message,
offset + plugin_offset + other_extmarks_offset,
need_to_be_under,
Expand Down
18 changes: 11 additions & 7 deletions lua/tiny-inline-diagnostic/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ local function forge_virt_texts_from_diagnostics(opts, diags, cursor_pos, buf)
buf
)

if need_to_be_under == false then
need_to_be_under = diag_need_to_be_under
if diag_need_to_be_under == true then
need_to_be_under = true
end

-- Remove new line if not needed
Expand All @@ -135,7 +135,7 @@ local function forge_virt_texts_from_diagnostics(opts, diags, cursor_pos, buf)

vim.list_extend(all_virtual_texts, virt_texts)
end
return all_virtual_texts, offset_win_col, overflow_last_line, need_to_be_under
return all_virtual_texts, offset_win_col, need_to_be_under
end

--- Function to get the diagnostic under the cursor.
Expand Down Expand Up @@ -199,11 +199,12 @@ local function apply_diagnostics_virtual_texts(opts, event)
)
end


local diag_overflow_last_line = false
local lines_count = vim.api.nvim_buf_line_count(event.buf)
local buf_lines_count = vim.api.nvim_buf_line_count(event.buf)

local total_lines = #virt_lines
if total_lines > lines_count then
if total_lines >= buf_lines_count - 1 then
diag_overflow_last_line = true
end

Expand All @@ -224,7 +225,9 @@ local function apply_diagnostics_virtual_texts(opts, event)
strict = false,
})
table.remove(virt_lines, 2)
if not diag_overflow_last_line then
win_col = 0

if curline < buf_lines_count - 1 then
curline = curline + 1
end
end
Expand All @@ -241,9 +244,10 @@ local function apply_diagnostics_virtual_texts(opts, event)
vim.api.nvim_buf_set_extmark(event.buf, diagnostic_ns, curline, 0, {
id = curline + 1,
line_hl_group = "CursorLine",
virt_text_pos = "eol",
virt_text_pos = "overlay",
virt_text = virt_lines[1],
virt_lines = other_virt_lines,
virt_text_win_col = win_col + offset,
priority = virt_prorioty,
strict = false,
})
Expand Down

0 comments on commit 23aca46

Please sign in to comment.