]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
connect digs virtual text display with autoHighlightDiags option
authorOleksiy Hryshchenko <greeschenko@gmail.com>
Tue, 28 Mar 2023 09:22:57 +0000 (12:22 +0300)
committerOleksiy Hryshchenko <greeschenko@gmail.com>
Tue, 28 Mar 2023 09:22:57 +0000 (12:22 +0300)
autoload/lsp/diag.vim
doc/lsp.txt

index d21e21d2fb783418582d4f4fcaa56d97b5769a87..3919ef49b5fdf812ea73fb6f7cb25778dfd919f4 100644 (file)
@@ -28,11 +28,18 @@ def DiagsRefreshSigns(lspserver: dict<any>, bnr: number)
   # Remove all the existing diagnostic signs
   sign_unplace('LSPDiag', {buffer: bnr})
 
-  if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
+  if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText && opt.lspOptions.autoHighlightDiags
       # Remove all virtual text
       prop_remove({type: 'LspDiagVirtualText', bufnr: bnr, all: true})
   endif
 
+  # remove add virtual text in all bufs if auto highlight digs off
+  if !opt.lspOptions.autoHighlightDiags
+      for binfo in getbufinfo({bufloaded: true})
+          prop_remove({type: 'LspDiagVirtualText', bufnr: binfo.bufnr, all: true})
+      endfor
+  endif
+
   if !lspserver.diagsMap->has_key(bnr) ||
       lspserver.diagsMap[bnr].sortedDiagnostics->empty()
     return
@@ -48,7 +55,7 @@ def DiagsRefreshSigns(lspserver: dict<any>, bnr: number)
                                lnum: lnum,
                                name: DiagSevToSignName(diag.severity)})
 
-    if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
+    if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText && opt.lspOptions.autoHighlightDiags
         prop_add( lnum, 0, {
             bufnr: bnr,
             type: 'LspDiagVirtualText',
@@ -397,9 +404,17 @@ enddef
 
 # Disable the LSP diagnostics highlighting in all the buffers
 export def DiagsHighlightDisable()
+  # turn off all diags highlight
+  opt.lspOptions.autoHighlightDiags = false
+  # refresh for removing diagnostic virtual text
+  for binfo in getbufinfo({bufloaded: true})
+    var lspserver: dict<any> = buf.BufLspServerGet(binfo.bufnr)
+    if !lspserver->empty() && lspserver.running
+      DiagsRefreshSigns(lspserver, binfo.bufnr)
+    endif
+  endfor
   # Remove all the existing diagnostic signs in all the buffers
   sign_unplace('LSPDiag')
-  opt.lspOptions.autoHighlightDiags = false
 enddef
 
 # Enable the LSP diagnostics highlighting
index da139ce504b298af0cf3da827fc1f621bbce5f81..c43e3135e82ff31a62bdcd6597c3b299ab64e761 100644 (file)
@@ -336,6 +336,7 @@ showInlayHints              |Boolean| option.  Show inlay hints from the language
                        version 9.0.0178 or later.
 showDiagWithVirtualText                |Boolean| option.  Show diagnostic messages text from the language
                        server with virtual text.  By default this is set to false.
+            Needs autoHighlightDiags == true
             Needs Vim version 9.0.1157 or later.
 diagVirtualTextHL              |String| option.
             The highlight group used for a diagnostics virtual text.