]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Cleanup of code duplications for diagnostics.
authorberggeist <24396556+berggeist@users.noreply.github.com>
Fri, 21 Apr 2023 18:45:16 +0000 (20:45 +0200)
committerberggeist <24396556+berggeist@users.noreply.github.com>
Fri, 21 Apr 2023 18:45:16 +0000 (20:45 +0200)
autoload/lsp/diag.vim

index 821c091c7f3241f6df378d7fc66babe5b2af17b3..b6daa3e16fd9e50e7a5a7ef6457a6fbdb9724f46 100644 (file)
@@ -129,10 +129,8 @@ def DiagSevToSymbolText(severity: number): string
   return typeMap[severity - 1]
 enddef
 
-# Refresh the placed diagnostics in buffer 'bnr'
-# This inline signs, inline props, and virtual text diagnostics
-def DiagsRefresh(bnr: number)
-  bnr->bufload()
+# Remove signs and text properties for diagnostics in buffer
+def RemoveDiagVisualsForBuffer(bnr: number)
   # Remove all the existing diagnostic signs
   sign_unplace('LSPDiag', {buffer: bnr})
 
@@ -148,6 +146,14 @@ def DiagsRefresh(bnr: number)
     prop_remove({type: 'LspDiagInlineInfo', bufnr: bnr, all: true})
     prop_remove({type: 'LspDiagInlineHint', bufnr: bnr, all: true})
   endif
+enddef
+
+# Refresh the placed diagnostics in buffer 'bnr'
+# This inline signs, inline props, and virtual text diagnostics
+def DiagsRefresh(bnr: number)
+  bnr->bufload()
+
+  RemoveDiagVisualsForBuffer(bnr)
 
   if !diagsMap->has_key(bnr) ||
       diagsMap[bnr].sortedDiagnostics->empty()
@@ -639,26 +645,9 @@ enddef
 export def DiagsHighlightDisable()
   # turn off all diags highlight
   opt.lspOptions.autoHighlightDiags = false
-
-  # Remove the diganostics virtual text in all the buffers.
-  if opt.lspOptions.showDiagWithVirtualText
-      || opt.lspOptions.highlightDiagInline
-    for binfo in getbufinfo({bufloaded: true})
-      # Remove all virtual text
-      if opt.lspOptions.showDiagWithVirtualText
-        prop_remove({type: 'LspDiagVirtualText', bufnr: binfo.bufnr, all: true})
-      endif
-      if opt.lspOptions.highlightDiagInline
-        prop_remove({type: 'LspDiagInlineError', bufnr: binfo.bufnr, all: true})
-        prop_remove({type: 'LspDiagInlineWarning', bufnr: binfo.bufnr, all: true})
-        prop_remove({type: 'LspDiagInlineInfo', bufnr: binfo.bufnr, all: true})
-        prop_remove({type: 'LspDiagInlineHint', bufnr: binfo.bufnr, all: true})
-      endif
-    endfor
-  endif
-
-  # Remove all the existing diagnostic signs in all the buffers
-  sign_unplace('LSPDiag')
+  for binfo in getbufinfo({bufloaded: true})
+      RemoveDiagVisualsForBuffer(binfo.bufnr)
+  endfor
 enddef
 
 # Enable the LSP diagnostics highlighting