@@ -580,17 +580,35 @@ require('lazy').setup({
580
580
[vim .diagnostic .severity .HINT ] = ' ' ,
581
581
},
582
582
} 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 ,
586
589
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
594
612
end ,
595
613
},
596
614
}
0 commit comments