Skip to content

Commit 27f902c

Browse files
committed
chore: use virtual lines for diagnostic messages
1 parent 0699a36 commit 27f902c

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

init.lua

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,17 +580,35 @@ require('lazy').setup({
580580
[vim.diagnostic.severity.HINT] = '󰌶 ',
581581
},
582582
} or {},
583-
virtual_text = {
584-
source = 'if_many',
585-
spacing = 2,
583+
-- virtual_text = {
584+
-- source = 'if_many',
585+
-- spacing = 2,
586+
-- },
587+
virtual_lines = {
588+
current_line = true,
586589
format = function(diagnostic)
587-
local diagnostic_message = {
588-
[vim.diagnostic.severity.ERROR] = diagnostic.message,
589-
[vim.diagnostic.severity.WARN] = diagnostic.message,
590-
[vim.diagnostic.severity.INFO] = diagnostic.message,
591-
[vim.diagnostic.severity.HINT] = diagnostic.message,
592-
}
593-
return diagnostic_message[diagnostic.severity]
590+
local message = diagnostic.message
591+
-- Get current window width and leave some margin for line numbers, etc.
592+
local win_width = vim.api.nvim_win_get_width(0) - 10 -- Adjust margin as needed
593+
local max_width = math.min(80, win_width) -- Use 80 or window width, whichever is smaller
594+
595+
if #message > max_width then
596+
local lines = {}
597+
local current_line = ''
598+
for word in message:gmatch '%S+' do
599+
if #current_line + #word + 1 > max_width then
600+
table.insert(lines, current_line)
601+
current_line = word
602+
else
603+
current_line = current_line == '' and word or current_line .. ' ' .. word
604+
end
605+
end
606+
if current_line ~= '' then
607+
table.insert(lines, current_line)
608+
end
609+
return table.concat(lines, '\n')
610+
end
611+
return message
594612
end,
595613
},
596614
}

0 commit comments

Comments
 (0)