@@ -628,33 +628,56 @@ require('lazy').setup({
628
628
629
629
-- Diagnostic Config
630
630
-- See :help vim.diagnostic.Opts
631
+ local diagnostic_icons = {
632
+ [vim .diagnostic .severity .ERROR ] = ' ' ,
633
+ [vim .diagnostic .severity .WARN ] = ' ' ,
634
+ [vim .diagnostic .severity .INFO ] = ' ' ,
635
+ [vim .diagnostic .severity .HINT ] = ' ' ,
636
+ }
637
+
631
638
vim .diagnostic .config {
639
+ update_in_insert = true ,
632
640
severity_sort = true ,
633
641
float = { border = ' rounded' , source = ' if_many' },
634
- underline = { severity = vim .diagnostic .severity .ERROR },
635
- signs = vim .g .have_nerd_font and {
636
- text = {
637
- [vim .diagnostic .severity .ERROR ] = ' ' ,
638
- [vim .diagnostic .severity .WARN ] = ' ' ,
639
- [vim .diagnostic .severity .INFO ] = ' ' ,
640
- [vim .diagnostic .severity .HINT ] = ' ' ,
641
- },
642
- } or {},
643
- virtual_text = {
644
- source = ' if_many' ,
645
- spacing = 2 ,
646
- format = function (diagnostic )
647
- local diagnostic_message = {
648
- [vim .diagnostic .severity .ERROR ] = diagnostic .message ,
649
- [vim .diagnostic .severity .WARN ] = diagnostic .message ,
650
- [vim .diagnostic .severity .INFO ] = diagnostic .message ,
651
- [vim .diagnostic .severity .HINT ] = diagnostic .message ,
652
- }
653
- return diagnostic_message [diagnostic .severity ]
654
- end ,
655
- },
642
+ underline = true , -- { severity = vim.diagnostic.severity.ERROR }
643
+ signs = vim .g .have_nerd_font and { text = diagnostic_icons } or {},
656
644
}
657
645
646
+ -- Diagnostic configuration similar to VS Code's Error Lens.
647
+ -- In insert mode, diagnostics are displayed as inline virtual text.
648
+ -- In normal mode, diagnostics are shown as virtual lines below the affected lines.
649
+ --- @param enable boolean
650
+ local function set_virtual_text (enable )
651
+ vim .diagnostic .config {
652
+ virtual_lines = not enable and {
653
+ format = function (diagnostic )
654
+ return (diagnostic_icons [diagnostic .severity ] or ' ' ) .. diagnostic .message
655
+ end ,
656
+ } or false ,
657
+ virtual_text = enable and {
658
+ source = ' if_many' ,
659
+ spacing = 2 ,
660
+ format = function (diagnostic )
661
+ return (diagnostic_icons [diagnostic .severity ] or ' ' ) .. diagnostic .message
662
+ end ,
663
+ } or false ,
664
+ }
665
+ end
666
+
667
+ set_virtual_text (false )
668
+
669
+ vim .api .nvim_create_autocmd (' InsertEnter' , {
670
+ callback = function ()
671
+ set_virtual_text (true )
672
+ end ,
673
+ })
674
+
675
+ vim .api .nvim_create_autocmd (' InsertLeave' , {
676
+ callback = function ()
677
+ set_virtual_text (false )
678
+ end ,
679
+ })
680
+
658
681
-- LSP servers and clients are able to communicate to each other what features they support.
659
682
-- By default, Neovim doesn't support everything that is in the LSP specification.
660
683
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
0 commit comments