autoload/lsp/hover.vim | 8 +++++--- autoload/lsp/lsp.vim | 4 ++-- autoload/lsp/lspserver.vim | 6 ++++-- plugin/lsp.vim | 2 +- test/clangd_tests.vim | 2 ++ diff --git a/autoload/lsp/hover.vim b/autoload/lsp/hover.vim index c90a4b34ebb4e10d455159f7f341ed7900f8193c..24ac702612999677acc78d03ea79a0cb76a56e55 100644 --- a/autoload/lsp/hover.vim +++ b/autoload/lsp/hover.vim @@ -72,17 +72,19 @@ enddef # process the 'textDocument/hover' reply from the LSP server # Result: Hover | null -export def HoverReply(lspserver: dict, hoverResult: any): void +export def HoverReply(lspserver: dict, 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 diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 7c86f8f43486d7556f7b8ee5d9e43b24b6854c86..e0cbf214323732f86fe7409015e046b6064bf07d 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -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 = buf.CurbufGetServer('hover') if lspserver->empty() || !lspserver.running || !lspserver.ready return endif - lspserver.hover() + lspserver.hover(cmdmods) enddef # show symbol references diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 31cb666f2ce97e24426aa7fc7022551ba5112716..ea99d8518ca0fdf51e6f413c4381a375c9d20d15 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -822,7 +822,7 @@ # get the hover information # Request: "textDocument/hover" # Param: HoverParams -def ShowHoverInfo(lspserver: dict): void +def ShowHoverInfo(lspserver: dict, 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 @@ # 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" diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 3aaf2014ca59cf1e046ecf6d19a9b6c558bad2f5..02db3975bbd60a877cc57094be9e821c06fe440b 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -75,7 +75,7 @@ command! -nargs=0 -bar LspGotoImpl lsp.GotoImplementation(v:false, ) command! -nargs=0 -bar LspGotoTypeDef lsp.GotoTypedef(v:false, ) 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() command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls() command! -nargs=0 -bar LspOutgoingCalls lsp.OutgoingCalls() command! -nargs=0 -bar LspOutline lsp.Outline() diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index 95a13bc1b97a2071801f26498741f687ae57e9ef..3fb5bbf8469710585af4eb27db1c44aacaa213da 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -992,6 +992,8 @@ popup_close(p[0]) 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.