From: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri, 28 Jul 2023 15:31:23 +0000 (-0700)
Subject: Move the code for displaying the current diag in the status line to diag.vim
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e117912131d18ece0c97248e142606da2844c56d;p=vim-lsp.git

Move the code for displaying the current diag in the status line to diag.vim
---

diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim
index 7eba712..880e08c 100644
--- a/autoload/lsp/diag.vim
+++ b/autoload/lsp/diag.vim
@@ -125,6 +125,16 @@ export def BufferInit(lspserver: dict<any>, bnr: number)
     :set ballooneval balloonevalterm
     setbufvar(bnr, '&balloonexpr', 'g:LspDiagExpr()')
   endif
+
+  var acmds: list<dict<any>> = []
+  # Show diagnostics on the status line
+  if opt.lspOptions.showDiagOnStatusLine
+    acmds->add({bufnr: bnr,
+		event: 'CursorMoved',
+		group: 'LSPBufferAutocmds',
+		cmd: 'ShowCurrentDiagInStatusLine()'})
+  endif
+  autocmd_add(acmds)
 enddef
 
 # Function to sort the diagnostics in ascending order based on the line and
@@ -641,7 +651,7 @@ export def ShowCurrentDiag(atPos: bool)
 enddef
 
 # Show the diagnostic message for the current line without linebreak
-export def ShowCurrentDiagInStatusLine()
+def ShowCurrentDiagInStatusLine()
   var bnr: number = bufnr()
   var lnum: number = line('.')
   var col: number = charcol('.')
@@ -653,9 +663,11 @@ export def ShowCurrentDiagInStatusLine()
     if diag->has_key('code')
       code = $'[{diag.code}] '
     endif
-    var msgNoLineBreak = code .. substitute(substitute(diag.message, "\n", ' ', ''), "\\n", ' ', '')
+    var msgNoLineBreak = code ..
+	diag.message->substitute("\n", ' ', '')->substitute("\\n", ' ', '')
     :echo msgNoLineBreak[ : max_width]
   else
+    # clear the previous message
     :echo ''
   endif
 enddef
diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim
index 7cf25ac..77544ff 100644
--- a/autoload/lsp/lsp.vim
+++ b/autoload/lsp/lsp.vim
@@ -387,14 +387,6 @@ def AddBufLocalAutocmds(lspserver: dict<any>, bnr: number): void
 		cmd: $'call LspDocHighlightClear({bnr}) | call LspDocHighlight({bnr}, "silent")'})
   endif
 
-  # Show diagnostics on the status line
-  if opt.lspOptions.showDiagOnStatusLine
-    acmds->add({bufnr: bnr,
-		event: 'CursorMoved',
-		group: 'LSPBufferAutocmds',
-		cmd: 'LspShowCurrentDiagInStatusLine()'})
-  endif
-
   autocmd_add(acmds)
 enddef
 
@@ -758,16 +750,6 @@ export def LspShowCurrentDiag(atPos: bool)
   diag.ShowCurrentDiag(atPos)
 enddef
 
-# Display the diagnostics for the current line in the status line.
-export def LspShowCurrentDiagInStatusLine()
-  var fname: string = @%
-  if fname->empty()
-    return
-  endif
-
-  diag.ShowCurrentDiagInStatusLine()
-enddef
-
 # get the count of diagnostics in the current buffer
 export def ErrorCount(): dict<number>
   var res = {Error: 0, Warn: 0, Info: 0, Hint: 0}