diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 6af75cf8..49473832 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -894,6 +894,15 @@ export def DiagsHighlightDisable() 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 154f861e..1ed7b8d2 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 @@ export def LspDiagCmd(args: string, cmdCount: number, force: bool) 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 a318be4b..c2743c48 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* @@ -85,6 +85,9 @@ The following commands are provided: :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. :LspDiag next Jump to the next diagnostic message for the current @@ -757,6 +760,11 @@ can map these commands to keys and make it easier to invoke them. 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 @@ diagnostic message: 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 dc3eeee8..b78644ea 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -1637,7 +1637,7 @@ def g:Test_LspDiagsSubcmd() 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"'],