From: Yegappan Lakshmanan Date: Mon, 15 Jan 2024 15:48:35 +0000 (-0800) Subject: Add support for scrolling the hover popup window. Fixes #423 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7103956d55561554491040a9e753c04dbc9eeb8f;p=vim-lsp.git Add support for scrolling the hover popup window. Fixes #423 --- diff --git a/autoload/lsp/hover.vim b/autoload/lsp/hover.vim index 4ee4e68..16f3835 100644 --- a/autoload/lsp/hover.vim +++ b/autoload/lsp/hover.vim @@ -70,6 +70,34 @@ def GetHoverText(lspserver: dict, hoverResult: any): list return ['', ''] enddef +# Key filter function for the hover popup window. +# Only keys to scroll the popup window are supported. +def HoverWinFilterKey(hoverWin: number, key: string): bool + var keyHandled = false + + if key == "\" + || key == "\" + || key == "\" + || key == "\" + || key == "\" + || key == "\" + || key == "\" + || key == "\" + || key == "\" + || key == "\" + # scroll the hover popup window + win_execute(hoverWin, $'normal! {key}') + keyHandled = true + endif + + if !keyHandled + # For any other key, close the hover window + hoverWin->popup_close() + endif + + return keyHandled +enddef + # process the 'textDocument/hover' reply from the LSP server # Result: Hover | null export def HoverReply(lspserver: dict, hoverResult: any, cmdmods: string): void @@ -101,7 +129,8 @@ export def HoverReply(lspserver: dict, hoverResult: any, cmdmods: string): maxwidth: 80, minwidth: 80, border: [0, 1, 0, 1], - borderchars: [' ']}) + borderchars: [' '], + filter: HoverWinFilterKey}) win_execute(winid, $'setlocal ft={hoverKind}') endif enddef diff --git a/doc/lsp.txt b/doc/lsp.txt index d45207c..d7c4bbd 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -878,9 +878,26 @@ can map these commands to keys and make it easier to invoke them. *:LspHover* :LspHover Show the documentation for the symbol under the cursor - in a popup window. If you want to show the symbol - documentation in the |preview-window| instead of in a - popup window set > + in a popup window. The following keys can be used to + scroll the popup window: + + - Scroll window downwards by a line. + - Scroll window downwards by 'scroll' + lines. + - Scroll window downards by a page. + - ditto. + - Scroll window upwards by a line. + - Scroll window upwards by 'scroll' + lines. + - Scroll window upwards by a page. + - ditto. + - Goto the first line + - Goto the last line + + Pressing any other key will close the popup window. + + If you want to show the symbol documentation in the + |preview-window| instead of in a popup window set > LspOptionsSet({'hoverInPreview': true}) <