]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Move the diag sign and prop type definitions to a separate function
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 28 Mar 2023 14:26:36 +0000 (07:26 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 28 Mar 2023 14:26:36 +0000 (07:26 -0700)
autoload/lsp/diag.vim
autoload/lsp/lsp.vim
doc/lsp.txt

index 1c33b8e013bd6cda414e12ad54240e4247940e6d..83ae122bc348f6767406dc545274da9793b4b624 100644 (file)
@@ -6,6 +6,29 @@ import './options.vim' as opt
 import './buffer.vim' as buf
 import './util.vim'
 
+# Initialize the signs and the text property type used for diagnostics.
+export def InitOnce()
+  var lineHL: string = opt.lspOptions.diagLineHL
+  # Signs used for LSP diagnostics
+  sign_define([{name: 'LspDiagError', text: 'E>', texthl: 'ErrorMsg',
+                                               linehl: lineHL},
+               {name: 'LspDiagWarning', text: 'W>', texthl: 'Search',
+                                               linehl: lineHL},
+               {name: 'LspDiagInfo', text: 'I>', texthl: 'Pmenu',
+                                               linehl: lineHL},
+               {name: 'LspDiagHint', text: 'H>', texthl: 'Question',
+                                               linehl: lineHL}])
+
+  if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
+    if !hlexists('LspDiagVirtualText')
+      hlset([{name: 'LspDiagVirtualText',
+             linksto: opt.lspOptions.diagVirtualTextHL}])
+    endif
+    prop_type_add('LspDiagVirtualText', {highlight: 'LspDiagVirtualText',
+                                        override: true})
+  endif
+enddef
+
 # Remove the diagnostics stored for buffer 'bnr'
 export def DiagRemoveFile(lspserver: dict<any>, bnr: number)
   if lspserver.diagsMap->has_key(bnr)
@@ -28,16 +51,9 @@ 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 && 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
+  if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
+    # Remove all the existing virtual text
+    prop_remove({type: 'LspDiagVirtualText', bufnr: bnr, all: true})
   endif
 
   if !lspserver.diagsMap->has_key(bnr) ||
@@ -55,13 +71,12 @@ def DiagsRefreshSigns(lspserver: dict<any>, bnr: number)
                                lnum: lnum,
                                name: DiagSevToSignName(diag.severity)})
 
-    if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText && opt.lspOptions.autoHighlightDiags
-        prop_add( lnum, 0, {
-            bufnr: bnr,
-            type: 'LspDiagVirtualText',
-            text: '┌─ ' .. diag.message,
-            text_align: 'above',
-            text_padding_left: diag.range.start.character})
+    if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
+      prop_add(lnum, 0, {bufnr: bnr,
+                        type: 'LspDiagVirtualText',
+                        text: $'┌─ {diag.message}',
+                        text_align: 'above',
+                        text_padding_left: diag.range.start.character})
     endif
   endfor
 
@@ -198,7 +213,7 @@ def DiagsUpdateLocList(lspserver: dict<any>, bnr: number): bool
 
   var LspQfId: number = 0
   if bnr->getbufvar('LspQfId', 0) != 0 &&
-                 getloclist(0, {id: b:LspQfId}).id == b:LspQfId
+               getloclist(0, {id: b:LspQfId}).id == b:LspQfId
     LspQfId = b:LspQfId
   endif
 
@@ -418,13 +433,15 @@ enddef
 export def DiagsHighlightDisable()
   # turn off all diags highlight
   opt.lspOptions.autoHighlightDiags = false
-  # refresh for removing diagnostic virtual text
+
+  # Remove the diganostics virtual text in all the buffers.
   for binfo in getbufinfo({bufloaded: true})
-    var lspserver: dict<any> = buf.BufLspServerGet(binfo.bufnr)
-    if !lspserver->empty() && lspserver.running
-      DiagsRefreshSigns(lspserver, binfo.bufnr)
+    if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
+      # Remove all virtual text
+      prop_remove({type: 'LspDiagVirtualText', bufnr: binfo.bufnr, all: true})
     endif
   endfor
+
   # Remove all the existing diagnostic signs in all the buffers
   sign_unplace('LSPDiag')
 enddef
index 3a89f21330f193d85af6c9024e183cdba704c488..3a9eafb56d971674c6bd2080fc59b2175b7a06d9 100644 (file)
@@ -31,28 +31,11 @@ var ftypeServerMap: dict<dict<any>> = {}
 var lspInitializedOnce = false
 
 def LspInitOnce()
-  var lineHL: string = opt.lspOptions.diagLineHL
-  # Signs used for LSP diagnostics
-  sign_define([{name: 'LspDiagError', text: 'E>', texthl: 'ErrorMsg',
-                                               linehl: lineHL},
-               {name: 'LspDiagWarning', text: 'W>', texthl: 'Search',
-                                               linehl: lineHL},
-               {name: 'LspDiagInfo', text: 'I>', texthl: 'Pmenu',
-                                               linehl: lineHL},
-               {name: 'LspDiagHint', text: 'H>', texthl: 'Question',
-                                               linehl: lineHL}])
-
   prop_type_add('LspTextRef', {highlight: 'Search', override: true})
   prop_type_add('LspReadRef', {highlight: 'DiffChange', override: true})
   prop_type_add('LspWriteRef', {highlight: 'DiffDelete', override: true})
 
-  if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText
-      if !hlexists('LspDiagVirtualText')
-          hlset([{name: 'LspDiagVirtualText', linksto: opt.lspOptions.diagVirtualTextHL}])
-      endif
-      prop_type_add('LspDiagVirtualText', {highlight: 'LspDiagVirtualText', override: true})
-  endif
-
+  diag.InitOnce()
   inlayhints.InitOnce()
 
   :set ballooneval balloonevalterm
index c43e3135e82ff31a62bdcd6597c3b299ab64e761..639ae12e064b0bd371a68e54d7fb19aed75e5731 100644 (file)
@@ -334,13 +334,13 @@ showInlayHints            |Boolean| option.  Show inlay hints from the language
                        server.  By default this is set to false.  The inlay
                        hint text is displayed as a virtual text.  Needs Vim
                        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.
-            By default uses "LineNr".
+showDiagWithVirtualText        |Boolean| option.  Show diagnostic message text from
+                       the language server with virtual text.  By default
+                       this is set to false.  The "autoHighlightDiags" option
+                       should be set to true.
+                       Needs Vim version 9.0.1157 or later.
+diagVirtualTextHL      |String| option.  The highlight group used for a
+                       diagnostics virtual text.  By default uses "LineNr".
 showSignature          |Boolean| option.  In insert mode, automatically show
                        the current symbol signature in a popup.
                        By default this is set to true.