]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add <mods> to ":LspHighlight"
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 16:30:18 +0000 (18:30 +0200)
This will allow you to run `:silent LspHighlight` to silent the error
message.

autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
plugin/lsp.vim

index f62403ebe5bf471f4e44e5342bab8db6b5b78d25..f909ded67f51a1ec5f9913ed4269a1fd564b25b4 100644 (file)
@@ -395,7 +395,7 @@ def AddBufLocalAutocmds(lspserver: dict<any>, 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<any> = buf.CurbufGetServerChecked('documentHighlight')
   if lspserver->empty()
     return
   endif
 
-  lspserver.docHighlight()
+  lspserver.docHighlight(cmdmods)
 enddef
 
 # clear the symbol reference highlight
index 911383ea83f23d7ac78712ea857966d2d6b8c455..6f4f559fba5268d6bb409d170c4497669a90e157 100644 (file)
@@ -868,9 +868,12 @@ enddef
 
 # process the 'textDocument/documentHighlight' reply from the LSP server
 # Result: DocumentHighlight[] | null
-def DocHighlightReply(bnr: number, lspserver: dict<any>, docHighlightReply: any): void
+def DocHighlightReply(lspserver: dict<any>, 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<any>): void
+def DocHighlight(lspserver: dict<any>, 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<any>): 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"
index c0f1eb575b8bace8a514f8b59f2f6cf31bf5eb42..4abb8b9bade1050c910df7e447ee2ffc348493fb 100644 (file)
@@ -73,7 +73,7 @@ command! -nargs=0 -bar LspGotoDeclaration lsp.GotoDeclaration(v:false, <q-mods>)
 command! -nargs=0 -bar LspGotoDefinition lsp.GotoDefinition(v:false, <q-mods>)
 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 LspHighlight call LspDocHighlight(<q-mods>)
 command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()
 command! -nargs=0 -bar LspHover lsp.Hover(<q-mods>)
 command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls()