Skip to content

Commit

Permalink
Add the ':LspDiag highlight toggle' command
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Oct 1, 2024
1 parent 04b5b04 commit 94177b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions autoload/lsp/diag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion autoload/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/clangd_tests.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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"'],
Expand Down

0 comments on commit 94177b3

Please sign in to comment.