]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Refresh the diag message signs when re-enabling diag highlighting
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 25 Oct 2022 02:50:09 +0000 (19:50 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 25 Oct 2022 02:50:09 +0000 (19:50 -0700)
autoload/lsp/diag.vim

index eb230d40645f0955a84e9f75b6af5ae380a0b9ad..ab22eb106b82fa64b8c2ff535db6fdd390ef7f62 100644 (file)
@@ -3,6 +3,7 @@ vim9script
 # Functions related to handling LSP diagnostics.
 
 import './options.vim' as opt
+import './buffer.vim' as buf
 import './util.vim'
 
 # Remove the diagnostics stored for buffer 'bnr'
@@ -21,6 +22,25 @@ def DiagSevToSignName(severity: number): string
   return typeMap[severity - 1]
 enddef
 
+# Refresh the signs placed in buffer 'bnr' on lines with a diagnostic message.
+def DiagsRefreshSigns(lspserver: dict<any>, bnr: number)
+  # Remove all the existing diagnostic signs
+  sign_unplace('LSPDiag', {buffer: bnr})
+
+  if lspserver.diagsMap[bnr]->empty()
+    return
+  endif
+
+  var signs: list<dict<any>> = []
+  for [lnum, diag] in lspserver.diagsMap[bnr]->items()
+    signs->add({id: 0, buffer: bnr, group: 'LSPDiag',
+                               lnum: str2nr(lnum),
+                               name: DiagSevToSignName(diag.severity)})
+  endfor
+
+  signs->sign_placelist()
+enddef
+
 # New LSP diagnostic messages received from the server for a file.
 # Update the signs placed in the buffer for this file
 def ProcessNewDiags(lspserver: dict<any>, bnr: number)
@@ -44,21 +64,7 @@ def ProcessNewDiags(lspserver: dict<any>, bnr: number)
     return
   endif
 
-  # Remove all the existing diagnostic signs
-  sign_unplace('LSPDiag', {buffer: bnr})
-
-  if lspserver.diagsMap[bnr]->empty()
-    return
-  endif
-
-  var signs: list<dict<any>> = []
-  for [lnum, diag] in lspserver.diagsMap[bnr]->items()
-    signs->add({id: 0, buffer: bnr, group: 'LSPDiag',
-                               lnum: str2nr(lnum),
-                               name: DiagSevToSignName(diag.severity)})
-  endfor
-
-  signs->sign_placelist()
+  DiagsRefreshSigns(lspserver, bnr)
 enddef
 
 # FIXME: Remove this function once the Vim bug (calling one exported function
@@ -284,8 +290,13 @@ enddef
 
 # Enable the LSP diagnostics highlighting
 export def DiagsHighlightEnable()
-  # Remove all the existing diagnostic signs in all the buffers
   opt.lspOptions.autoHighlightDiags = true
+  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
 enddef
 
 # vim: shiftwidth=2 softtabstop=2