Skip to content

Commit

Permalink
Add support for toggling inlay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Sep 23, 2024
1 parent 6e665ab commit 04b5b04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 9 additions & 0 deletions autoload/lsp/inlayhints.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion autoload/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -809,14 +809,16 @@ 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
enddef

# Command-line completion for the ":LspInlayHints" command
export def LspInlayHintsComplete(arglead: string, cmdline: string, cursorPos: number): list<string>
var l = ['enable', 'disable']
var l = ['enable', 'disable', 'toggle']
return filter(l, (_, val) => val =~ $'^{arglead}')
enddef

Expand Down
14 changes: 8 additions & 6 deletions doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 04b5b04

@Konfekt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once at it, how about LspDiag highlight toggleinstead of custom creations such as

def g:LspHighlightDiagsToggle()
  if g:LspOptionsGet().autoHighlightDiags
    LspDiag highlight disable
	  g:LspOptionsSet({'autoHighlightDiags': false})
  else
    LspDiag highlight enable
	  g:LspOptionsSet({'autoHighlightDiags': true})
  endif
enddef

Please sign in to comment.