]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add support for scrolling the hover popup window. Fixes #423
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 15 Jan 2024 15:48:35 +0000 (07:48 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 15 Jan 2024 15:48:35 +0000 (07:48 -0800)
autoload/lsp/hover.vim
doc/lsp.txt

index 4ee4e684e5cce55ce2933ce71b257286f0a5950c..16f3835218298504938c28cc71b752bf590f4baf 100644 (file)
@@ -70,6 +70,34 @@ def GetHoverText(lspserver: dict<any>, hoverResult: any): list<any>
   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 == "\<C-E>"
+      || key == "\<C-D>"
+      || key == "\<C-F>"
+      || key == "\<PageDown>"
+      || key == "\<C-Y>"
+      || key == "\<C-U>"
+      || key == "\<C-B>"
+      || key == "\<PageUp>"
+      || key == "\<C-Home>"
+      || key == "\<C-End>"
+    # 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<any>, hoverResult: any, cmdmods: string): void
@@ -101,7 +129,8 @@ export def HoverReply(lspserver: dict<any>, 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
index d45207cb5d5bc0a7067c333b80e67cde5a1953c5..d7c4bbd8026cdc83d928b529f6c1310d41357e44 100644 (file)
@@ -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:
+
+                           <CTRL-E> - Scroll window downwards by a line.
+                           <CTRL-D> - Scroll window downwards by 'scroll'
+                                      lines.
+                           <CTRL-F> - Scroll window downards by a page.
+                           <PageDown> - ditto.
+                           <CTRL-Y> - Scroll window upwards by a line.
+                           <CTRL-U> - Scroll window upwards by 'scroll'
+                                      lines.
+                           <CTRL-B> - Scroll window upwards by a page.
+                           <PageUp> - ditto.
+                           <CTRL-Home> - Goto the first line
+                           <CTRL-End>  - 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})
 <