From 224ed94754a276d47fda3be86520fee4c195e3b6 Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Sun, 16 Apr 2023 09:40:12 +0200 Subject: [PATCH] Add to ":LspHighlight" This will allow you to run `:silent LspHighlight` to silent the error message. --- autoload/lsp/lsp.vim | 6 +++--- autoload/lsp/lspserver.vim | 14 +++++++++----- plugin/lsp.vim | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index f62403e..f909ded 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -395,7 +395,7 @@ def AddBufLocalAutocmds(lspserver: dict, bnr: number): void acmds->add({bufnr: bnr, event: 'CursorMoved', group: 'LSPBufferAutocmds', - cmd: 'call LspDocHighlightClear() | call LspDocHighlight()'}) + cmd: 'call LspDocHighlightClear() | call LspDocHighlight("silent")'}) endif # Show diagnostics on the status line @@ -757,13 +757,13 @@ export def ShowReferences(peek: bool) enddef # highlight all the places where a symbol is referenced -def g:LspDocHighlight() +def g:LspDocHighlight(cmdmods: string = '') var lspserver: dict = buf.CurbufGetServerChecked('documentHighlight') if lspserver->empty() return endif - lspserver.docHighlight() + lspserver.docHighlight(cmdmods) enddef # clear the symbol reference highlight diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 911383e..6f4f559 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -868,9 +868,12 @@ enddef # process the 'textDocument/documentHighlight' reply from the LSP server # Result: DocumentHighlight[] | null -def DocHighlightReply(bnr: number, lspserver: dict, docHighlightReply: any): void +def DocHighlightReply(lspserver: dict, docHighlightReply: any, + bnr: number, cmdmods: string): void if docHighlightReply->empty() - util.WarnMsg($'No highlight for the current position') + if cmdmods !~ 'silent' + util.WarnMsg($'No highlight for the current position') + endif return endif @@ -898,7 +901,7 @@ enddef # Request: "textDocument/documentHighlight" # Param: DocumentHighlightParams -def DocHighlight(lspserver: dict): void +def DocHighlight(lspserver: dict, cmdmods: string): void # Check whether LSP server supports getting highlight information if !lspserver.isDocumentHighlightProvider util.ErrMsg('Error: LSP server does not support document highlight') @@ -908,8 +911,9 @@ def DocHighlight(lspserver: dict): void # interface DocumentHighlightParams # interface TextDocumentPositionParams var params = GetLspTextDocPosition(false) - lspserver.rpc_a('textDocument/documentHighlight', params, - function('DocHighlightReply', [bufnr()])) + lspserver.rpc_a('textDocument/documentHighlight', params, (_, reply) => { + DocHighlightReply(lspserver, reply, bufnr(), cmdmods) + }) enddef # Request: "textDocument/documentSymbol" diff --git a/plugin/lsp.vim b/plugin/lsp.vim index c0f1eb5..4abb8b9 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -73,7 +73,7 @@ command! -nargs=0 -bar LspGotoDeclaration lsp.GotoDeclaration(v:false, ) command! -nargs=0 -bar LspGotoDefinition lsp.GotoDefinition(v:false, ) 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 LspHighlight call LspDocHighlight() command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear() command! -nargs=0 -bar LspHover lsp.Hover() command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls() -- 2.50.0