From e95b50beb4cd3bd04833b0e509f7a1d3d8d7e805 Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Sun, 16 Apr 2023 09:40:12 +0200 Subject: [PATCH] Add to hover 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 | 8 +++++--- autoload/lsp/lsp.vim | 4 ++-- autoload/lsp/lspserver.vim | 6 ++++-- plugin/lsp.vim | 2 +- test/clangd_tests.vim | 2 ++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/autoload/lsp/hover.vim b/autoload/lsp/hover.vim index c90a4b3..24ac702 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 7c86f8f..e0cbf21 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 31cb666..ea99d85 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -822,7 +822,7 @@ enddef # 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 @@ def ShowHoverInfo(lspserver: dict): 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" diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 3aaf201..02db397 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 95a13bc..3fb5bbf 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -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. -- 2.50.0