From 04b5b04312e641a3644994b332163cc5b668fb36 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 22 Sep 2024 20:12:08 -0700 Subject: [PATCH] Add support for toggling inlay hints --- autoload/lsp/inlayhints.vim | 9 +++++++++ autoload/lsp/lsp.vim | 4 +++- doc/lsp.txt | 14 ++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/autoload/lsp/inlayhints.vim b/autoload/lsp/inlayhints.vim index a7936997..5030c954 100644 --- a/autoload/lsp/inlayhints.vim +++ b/autoload/lsp/inlayhints.vim @@ -222,6 +222,15 @@ export def InlayHintsDisable() save_showInlayHints = false enddef +# Toggle (enable or disable) inlay hints. +export def InlayHintsToggle() + if opt.lspOptions.showInlayHints + InlayHintsDisable() + else + InlayHintsEnable() + endif +enddef + # Some options are changed. If 'showInlayHints' option is changed, then # either enable or disable inlay hints. export def LspInlayHintsOptionsChanged() diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 83f1f4d3..154f861e 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -809,6 +809,8 @@ export def InlayHints(ctl: string) inlayhints.InlayHintsEnable() elseif ctl == 'disable' inlayhints.InlayHintsDisable() + elseif ctl == 'toggle' + inlayhints.InlayHintsToggle() else util.ErrMsg($'LspInlayHints - Unsupported argument "{ctl}"') endif @@ -816,7 +818,7 @@ enddef # Command-line completion for the ":LspInlayHints" command export def LspInlayHintsComplete(arglead: string, cmdline: string, cursorPos: number): list - var l = ['enable', 'disable'] + var l = ['enable', 'disable', 'toggle'] return filter(l, (_, val) => val =~ $'^{arglead}') enddef diff --git a/doc/lsp.txt b/doc/lsp.txt index a40da7ad..a318be4b 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -117,7 +117,7 @@ The following commands are provided: in a popup window. :LspIncomingCalls Display the list of symbols calling the current symbol in a window. -:LspInlayHints Enable or disable inlay hints. +:LspInlayHints Enable or disable or toggle inlay hints. :LspOutgoingCalls Display the list of symbols called by the current symbol in a window. :LspOutline Show the list of symbols defined in the current file @@ -937,11 +937,13 @@ can map these commands to keys and make it easier to invoke them. not all the language servers support this feature. *:LspInlayHints* -:LspInlayHints Enable or disable inlay hints. Supports the "enable" - and "disable" arguments. When "enable" is specified, - enables the inlay hints for all the buffers with a - language server that supports inlay hints. When - "disable" is specified, disables the inlay hints. +:LspInlayHints Enable or disable inlay hints. Supports the "enable", + "disable" and "toggle" arguments. When "enable" is + specified, enables the inlay hints for all the buffers + with a language server that supports inlay hints. + When "disable" is specified, disables the inlay hints. + When "toggle" is specified, either enables or disables + the inlay hints. *:LspOutoingCalls* :LspOutgoingCalls Display a hierarchy of symbols called by the symbol