]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add <mods> to hover
authorAndreas Louv <andreas@louv.dk>
Sun, 16 Apr 2023 07:40:12 +0000 (09:40 +0200)
committerAndreas Louv <andreas@louv.dk>
Sun, 16 Apr 2023 08:06:23 +0000 (10:06 +0200)
This will allow you to run `:silent LspHover` to silent the error
message, and things `:belowright LspHover` to position the preview
window.

autoload/lsp/hover.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
plugin/lsp.vim
test/clangd_tests.vim

index c90a4b34ebb4e10d455159f7f341ed7900f8193c..24ac702612999677acc78d03ea79a0cb76a56e55 100644 (file)
@@ -72,17 +72,19 @@ enddef
 
 # process the 'textDocument/hover' reply from the LSP server
 # Result: Hover | null
-export def HoverReply(lspserver: dict<any>, hoverResult: any): void
+export def HoverReply(lspserver: dict<any>, hoverResult: any, cmdmods: string): void
   var [hoverText, hoverKind] = GetHoverText(lspserver, hoverResult)
 
   # Nothing to show
   if hoverText->empty()
-    util.WarnMsg($'No hover messages found for current position')
+    if cmdmods !~ 'silent'
+      util.WarnMsg($'No hover messages found for current position')
+    endif
     return
   endif
 
   if opt.lspOptions.hoverInPreview
-    :silent! pedit LspHoverReply
+    execute $':silent! {cmdmods} pedit LspHoverReply'
     :wincmd P
     :setlocal buftype=nofile
     :setlocal bufhidden=delete
index 7c86f8f43486d7556f7b8ee5d9e43b24b6854c86..e0cbf214323732f86fe7409015e046b6064bf07d 100644 (file)
@@ -737,13 +737,13 @@ enddef
 
 # Display the hover message from the LSP server for the current cursor
 # location
-export def Hover()
+export def Hover(cmdmods: string)
   var lspserver: dict<any> = buf.CurbufGetServer('hover')
   if lspserver->empty() || !lspserver.running || !lspserver.ready
     return
   endif
 
-  lspserver.hover()
+  lspserver.hover(cmdmods)
 enddef
 
 # show symbol references
index 31cb666f2ce97e24426aa7fc7022551ba5112716..ea99d8518ca0fdf51e6f413c4381a375c9d20d15 100644 (file)
@@ -822,7 +822,7 @@ enddef
 # get the hover information
 # Request: "textDocument/hover"
 # Param: HoverParams
-def ShowHoverInfo(lspserver: dict<any>): void
+def ShowHoverInfo(lspserver: dict<any>, cmdmods: string): void
   # Check whether LSP server supports getting hover information.
   # caps->hoverProvider can be a "boolean" or "HoverOptions"
   if !lspserver.isHoverProvider
@@ -832,7 +832,9 @@ def ShowHoverInfo(lspserver: dict<any>): void
   # interface HoverParams
   #   interface TextDocumentPositionParams
   var params = GetLspTextDocPosition(false)
-  lspserver.rpc_a('textDocument/hover', params, hover.HoverReply)
+  lspserver.rpc_a('textDocument/hover', params, (_, reply) => {
+    hover.HoverReply(lspserver, reply, cmdmods)
+  })
 enddef
 
 # Request: "textDocument/references"
index 3aaf2014ca59cf1e046ecf6d19a9b6c558bad2f5..02db3975bbd60a877cc57094be9e821c06fe440b 100644 (file)
@@ -75,7 +75,7 @@ command! -nargs=0 -bar LspGotoImpl lsp.GotoImplementation(v:false, <q-mods>)
 command! -nargs=0 -bar LspGotoTypeDef lsp.GotoTypedef(v:false, <q-mods>)
 command! -nargs=0 -bar LspHighlight call LspDocHighlight()
 command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()
-command! -nargs=0 -bar LspHover lsp.Hover()
+command! -nargs=0 -bar LspHover lsp.Hover(<q-mods>)
 command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls()
 command! -nargs=0 -bar LspOutgoingCalls lsp.OutgoingCalls()
 command! -nargs=0 -bar LspOutline lsp.Outline()
index 95a13bc1b97a2071801f26498741f687ae57e9ef..3fb5bbf8469710585af4eb27db1c44aacaa213da 100644 (file)
@@ -992,6 +992,8 @@ def g:Test_LspHover()
   cursor(7, 1)
   output = execute(':LspHover')->split("\n")
   assert_equal('No hover messages found for current position', output[0])
+  output = execute(':silent LspHover')->split("\n")
+  assert_equal([], output)
   assert_equal([], popup_list())
 
   # Show current diagnostic as to open another popup.