]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add LspDiag nextWrap and prevWrap command args
authorNick Jensen <nickspoon@gmail.com>
Mon, 18 Mar 2024 22:03:23 +0000 (11:03 +1300)
committerNick Jensen <nickspoon@gmail.com>
Mon, 18 Mar 2024 22:03:23 +0000 (11:03 +1300)
README.md
autoload/lsp/diag.vim
autoload/lsp/lsp.vim
doc/lsp.txt
plugin/lsp.vim

index 011bfe26fb5324b12fa08bf856831dc0dd2707d4..ba2f4810527b5df5735d4850652d1c54628c9a5b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -185,7 +185,9 @@ Command|Description
 :LspDiag highlight disable|Disable diagnostic message highlights.
 :LspDiag highlight enable|Enable diagnostic message highlights.
 :LspDiag next|Jump to the next diagnostic message after the current position.
+:LspDiag nextWrap|Jump to the next diagnostic message after the current position, wrapping to the first message when the last message is reached.
 :LspDiag prev|Jump to the previous diagnostic message before the current position.
+:LspDiag prevWrap|Jump to the previous diagnostic message before the current position, wrapping to the last message when the first message is reached.
 :LspDiag show|Display the diagnostics messages from the language server for the current buffer in a new location list.
 :LspDocumentSymbol|Display the symbols in the current file in a popup menu and jump to the selected symbol.
 :LspFold|Fold the current file.
index acf073679462bd4b17bc9863ea7c98ed178bbd6e..6975edf8713936515ebba5722a83cea871078c3f 100644 (file)
@@ -775,13 +775,13 @@ export def LspDiagsJump(which: string, a_count: number = 0): void
   var count = a_count > 1 ? a_count : 1
   var curlnum: number = line('.')
   var curcol: number = charcol('.')
-  for diag in (which == 'next' || which == 'here') ?
+  for diag in (which == 'next' || which == 'nextWrap' || which == 'here') ?
                                        diags : diags->copy()->reverse()
     var d_start = diag.range.start
     var lnum = d_start.line + 1
     var col = util.GetCharIdxWithoutCompChar(bnr, d_start) + 1
-    if (which == 'next' && (lnum > curlnum || lnum == curlnum && col > curcol))
-         || (which == 'prev' && (lnum < curlnum || lnum == curlnum
+    if ((which == 'next' || which == 'nextWrap') && (lnum > curlnum || lnum == curlnum && col > curcol))
+         || ((which == 'prev' || which == 'prevWrap') && (lnum < curlnum || lnum == curlnum
                                                        && col < curcol))
          || (which == 'here' && (lnum == curlnum && col >= curcol))
 
@@ -797,17 +797,22 @@ export def LspDiagsJump(which: string, a_count: number = 0): void
   endfor
 
   # If [count] exceeded the remaining diags
-  if which == 'next' && a_count > 1 && a_count != count
+  if ((which == 'next' || which == 'nextWrap') && a_count > 1 && a_count != count)
     JumpDiag(diags[-1])
     return
   endif
 
   # If [count] exceeded the previous diags
-  if which == 'prev' && a_count > 1 && a_count != count
+  if ((which == 'prev' || which == 'prevWrap') && a_count > 1 && a_count != count)
     JumpDiag(diags[0])
     return
   endif
 
+  if which == 'nextWrap' || which == 'prevWrap'
+    JumpDiag(diags[which == 'nextWrap' ? 0 : -1])
+    return
+  endif
+
   if which == 'here'
     util.WarnMsg('No more diagnostics found on this line')
   else
index 3dfd7ab726589eb548983d70b5e1d2d073bd3f7b..507eb00f3ec8dd69a1f1690b41cdb5baf4bc69cd 100644 (file)
@@ -1161,8 +1161,8 @@ enddef
 export def LspDiagComplete(arglead: string, cmdline: string, cursorPos: number): list<string>
   var wordBegin = -1
   var wordEnd = -1
-  var l = ['first', 'current', 'here', 'highlight', 'last', 'next', 'prev',
-          'show']
+  var l = ['first', 'current', 'here', 'highlight', 'last', 'next', 'nextWrap',
+           'prev', 'prevWrap', 'show']
 
   # Skip the command name
   var i = cmdline->stridx(' ', 0)
@@ -1209,8 +1209,12 @@ export def LspDiagCmd(args: string, cmdCount: number, force: bool)
     diag.LspDiagsJump('last', 0)
   elseif args == 'next'
     diag.LspDiagsJump('next', cmdCount)
+  elseif args == 'nextWrap'
+    diag.LspDiagsJump('nextWrap', cmdCount)
   elseif args == 'prev'
     diag.LspDiagsJump('prev', cmdCount)
+  elseif args == 'prevWrap'
+    diag.LspDiagsJump('prevWrap', cmdCount)
   elseif args == 'show'
     ShowDiagnostics()
   else
index 3c1e3fc9aba83881ea6901b63c8189b80af8d463..1987bde75f540da33678e5c0d0b8b2fb127f1dff 100644 (file)
@@ -88,8 +88,16 @@ The following commands are provided:
                        buffer.
 :LspDiag next          Jump to the next diagnostic message for the current
                        buffer after the current cursor position.
+:LspDiag nextWrap      Jump to the next diagnostic message for the current
+                       buffer after the current cursor position.
+                       Wrap back to the first message when no more messages
+                       are found.
 :LspDiag prev          Jump to the previous diagnostic message for the
                        current buffer before the current current position.
+:LspDiag prevWrap      Jump to the previous diagnostic message for the
+                       current buffer before the current current position.
+                       Wrap back to the last message when no previous
+                       messages are found.
 :LspDiag show          Display the diagnostics messages from the language
                        server for the current buffer in a location list.
 :LspDocumentSymbol     Display the symbols in the current file in a popup
index 9125b6eb65f5306d625eb1863b43a83058d30153..3b3815a168288fa1d5361b85cc79e69ba817b9fa 100644 (file)
@@ -67,7 +67,9 @@ command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(<bang>false)
 command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first')
 command! -nargs=0 -bar LspDiagLast lsp.JumpToDiag('last')
 command! -nargs=0 -bar -count=1 LspDiagNext lsp.JumpToDiag('next', <count>)
+command! -nargs=0 -bar -count=1 LspDiagNextWrap lsp.JumpToDiag('nextWrap', <count>)
 command! -nargs=0 -bar -count=1 LspDiagPrev lsp.JumpToDiag('prev', <count>)
+command! -nargs=0 -bar -count=1 LspDiagPrevWrap lsp.JumpToDiag('prevWrap', <count>)
 command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics()
 command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here')
 command! -nargs=0 -bar LspDocumentSymbol lsp.ShowDocSymbols()