]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add the ':LspDiag highlight toggle' command
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 1 Oct 2024 02:13:06 +0000 (19:13 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 1 Oct 2024 02:13:06 +0000 (19:13 -0700)
autoload/lsp/diag.vim
autoload/lsp/lsp.vim
doc/lsp.txt
test/clangd_tests.vim

index 6af75cf88eaefc5ad3469e741e28c33ee97ba829..49473832f06394378f5a7abd52e068332f581c12 100644 (file)
@@ -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()
index 154f861e9e08e91922b899717e5c4b944da70927..1ed7b8d2541b0f3ca6efbc7381b47fc9bc399448 100644 (file)
@@ -1177,7 +1177,7 @@ enddef
 
 # Command-line completion for the ":LspDiag highlight" command
 def LspDiagHighlightComplete(arglead: string, cmdline: string, cursorPos: number): list<string>
-  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
index a318be4b0678b60e29fa7eb7fd0b5492c69ca913..c2743c48a2b8cc88fc891c8d5379f3109e4efaca 100644 (file)
@@ -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
index dc3eeee8a7ca2603f0555573f7ad07806e0710b2..b78644eabcd089a19bed07fe695914e2ba9eeeb8 100644 (file)
@@ -1637,7 +1637,7 @@ def g:Test_LspDiagsSubcmd()
   feedkeys(":LspDiag \<C-A>\<CR>", 'xt')
   assert_equal('LspDiag first current here highlight last next nextWrap prev prevWrap show', @:)
   feedkeys(":LspDiag highlight \<C-A>\<CR>", '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"'],