]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Make it possible to provide a "[count]" for ":LspDiagNext"
authorAndreas Louv <andreas@louv.dk>
Mon, 3 Apr 2023 00:00:21 +0000 (02:00 +0200)
committerAndreas Louv <andreas@louv.dk>
Mon, 3 Apr 2023 00:52:13 +0000 (02:52 +0200)
This works somewhat like the count for `:h :cafter`

autoload/lsp/diag.vim
autoload/lsp/lsp.vim
plugin/lsp.vim

index cfca785a3f09a72f2063d21df547f104a9d629a9..bdf36a4223e275d123972b3a81fb6bd2ce224ac3 100644 (file)
@@ -457,8 +457,17 @@ export def GetDiagsByLine(lspserver: dict<any>, bnr: number, lnum: number): list
   return []
 enddef
 
+# Utility function to do the actual jump
+def JumpDiag(diag: dict<any>)
+    setcursorcharpos(diag.range.start.line + 1, diag.range.start.character + 1)
+    if !opt.lspOptions.showDiagWithVirtualText
+      :redraw
+      DisplayDiag(diag)
+    endif
+enddef
+
 # jump to the next/previous/first diagnostic message in the current buffer
-export def LspDiagsJump(lspserver: dict<any>, which: string): void
+export def LspDiagsJump(lspserver: dict<any>, which: string, a_count: number = 0): void
   var fname: string = expand('%:p')
   if fname == ''
     return
@@ -474,15 +483,12 @@ export def LspDiagsJump(lspserver: dict<any>, which: string): void
   var diags = lspserver.diagsMap[bnr].sortedDiagnostics
 
   if which == 'first'
-    setcursorcharpos(diags[0].range.start.line + 1, diags[0].range.start.character + 1)
-    if !opt.lspOptions.showDiagWithVirtualText
-      :redraw
-      DisplayDiag(diags[0])
-    endif
+    JumpDiag(diags[0])
     return
   endif
 
   # Find the entry just before the current line (binary search)
+  var count = a_count > 1 ? a_count : 1
   var curlnum: number = line('.')
   var curcol: number = charcol('.')
   for diag in (which == 'next' || which == 'here') ?
@@ -493,15 +499,24 @@ export def LspDiagsJump(lspserver: dict<any>, which: string): void
          || (which == 'prev' && (lnum < curlnum || lnum == curlnum
                                                        && col < curcol))
          || (which == 'here' && (lnum == curlnum && col >= curcol))
-      setcursorcharpos(lnum, col)
-      if !opt.lspOptions.showDiagWithVirtualText
-       :redraw
-       DisplayDiag(diag)
+
+      # Skip over as many diags as "count" dictates
+      count = count - 1
+      if count > 0
+        continue
       endif
+
+      JumpDiag(diag)
       return
     endif
   endfor
 
+  # If [count] exceeded the remaining diags
+  if which == 'next' && a_count > 1 && a_count != count
+    JumpDiag(diags[-1])
+    return
+  endif
+
   if which == 'here'
     util.WarnMsg('Error: No more diagnostics found on this line')
   else
index 21423b19b7847aecc64f3066872a7886d9604f03..fd26217d8ad6539e12cc4357151aeaf1b60375dd 100644 (file)
@@ -596,13 +596,13 @@ export def ErrorCount(): dict<number>
 enddef
 
 # jump to the next/previous/first diagnostic message in the current buffer
-export def JumpToDiag(which: string): void
+export def JumpToDiag(which: string, count: number = 0): void
   var lspserver: dict<any> = buf.CurbufGetServerChecked()
   if lspserver->empty()
     return
   endif
 
-  diag.LspDiagsJump(lspserver, which)
+  diag.LspDiagsJump(lspserver, which, count)
 enddef
 
 # Display the hover message from the LSP server for the current cursor
index 7648257b78851ca1a2e29dda969312cdf1250d33..8d2ea9d9bbd4a510d324312882938e09356f2f0d 100644 (file)
@@ -82,7 +82,7 @@ command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(<bang>false)
 command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first')
 command! -nargs=0 -bar LspDiagHighlightDisable lsp.DiagHighlightDisable()
 command! -nargs=0 -bar LspDiagHighlightEnable lsp.DiagHighlightEnable()
-command! -nargs=0 -bar LspDiagNext lsp.JumpToDiag('next')
+command! -nargs=0 -bar -count=1 LspDiagNext lsp.JumpToDiag('next', <count>)
 command! -nargs=0 -bar LspDiagPrev lsp.JumpToDiag('prev')
 command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics()
 command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here')