autoload/lsp/diag.vim | 9 +++++++++ autoload/lsp/lsp.vim | 4 +++- doc/lsp.txt | 13 +++++++++++-- test/clangd_tests.vim | 2 +- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 6af75cf88eaefc5ad3469e741e28c33ee97ba829..49473832f06394378f5a7abd52e068332f581c12 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -894,6 +894,15 @@ endif endfor enddef +# Toggle the LSP diagnostics highlighting in all the buffers +export def DiagsHighlightToggle() + if opt.lspOptions.autoHighlightDiags + DiagsHighlightDisable() + else + DiagsHighlightEnable() + endif +enddef + # Some options are changed. If 'autoHighlightDiags' option is changed, then # either enable or disable diags auto highlight. export def LspDiagsOptionsChanged() diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 154f861e9e08e91922b899717e5c4b944da70927..1ed7b8d2541b0f3ca6efbc7381b47fc9bc399448 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -1177,7 +1177,7 @@ enddef # Command-line completion for the ":LspDiag highlight" command def LspDiagHighlightComplete(arglead: string, cmdline: string, cursorPos: number): list - return LspSubCmdComplete(['enable', 'disable'], arglead, cmdline, cursorPos) + return LspSubCmdComplete(['enable', 'disable', 'toggle'], arglead, cmdline, cursorPos) enddef # Command-line completion for the ":LspDiag" command @@ -1216,6 +1216,8 @@ if subcmd == 'enable' diag.DiagsHighlightEnable() elseif subcmd == 'disable' diag.DiagsHighlightDisable() + elseif subcmd == 'toggle' + diag.DiagsHighlightToggle() else util.ErrMsg($':LspDiag highlight - Unsupported argument "{subcmd}"') endif diff --git a/doc/lsp.txt b/doc/lsp.txt index a318be4b0678b60e29fa7eb7fd0b5492c69ca913..c2743c48a2b8cc88fc891c8d5379f3109e4efaca 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -3,7 +3,7 @@ Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) For Vim version 9.0 and above -Last change: Feb 13, 2024 +Last change: Sep 30, 2024 ============================================================================== CONTENTS *lsp-contents* @@ -84,6 +84,9 @@ Disable highlighting lines with a diagnostic message for the current Vim session. :LspDiag highlight enable Enable highlighting lines with a diagnostic message + for the current Vim session. +:LspDiag highlight toggle + Toggle highlighting lines with a diagnostic message for the current Vim session. :LspDiag last Jump to the last diagnostic message for the current buffer. @@ -757,6 +760,11 @@ Enable highlighting lines with a diagnostic message for the current Vim session. Note that highlighting lines with a diagnostic message is enabled by default. +:LspDiag highlight toggle *:LspDiag-highlight-toggle* + Toggle (enable or disable) highlighting lines with a + diagnostic message for the current Vim session in all + the buffers. + *:LspDiag-last* :LspDiag last Jumps to the location of the first diagnostic message for the current file. @@ -1458,7 +1466,8 @@ If you wish to temporarily disable the automatic diagnostic highlighting for the current Vim session, you can achieve this using the ":LspDiag highlight disable" command. When you want to re-enable the highlighting, you can use -the ":LspDiag highlight enable" command. +the ":LspDiag highlight enable" command. To toggle the highlighting, you can +use the ":LspDiag highlight toggle" command. To permanently disable the automatic highlighting of diagnostics, you can set the "autoHighlightDiags" option to |v:false| in your .vimrc file. This diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index dc3eeee8a7ca2603f0555573f7ad07806e0710b2..b78644eabcd089a19bed07fe695914e2ba9eeeb8 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -1637,7 +1637,7 @@ feedkeys(":LspDiag \\", 'xt') assert_equal('LspDiag first current here highlight last next nextWrap prev prevWrap show', @:) feedkeys(":LspDiag highlight \\", 'xt') - assert_equal('LspDiag highlight enable disable', @:) + assert_equal('LspDiag highlight enable disable toggle', @:) assert_equal(['Error: :LspDiag - Unsupported argument "xyz"'], execute('LspDiag xyz')->split("\n")) assert_equal(['Error: :LspDiag - Unsupported argument "first xyz"'],