README.md | 2 ++ autoload/lsp/diag.vim | 15 ++++++++++----- autoload/lsp/lsp.vim | 8 ++++++-- doc/lsp.txt | 8 ++++++++ plugin/lsp.vim | 2 ++ diff --git a/README.md b/README.md index 011bfe26fb5324b12fa08bf856831dc0dd2707d4..ba2f4810527b5df5735d4850652d1c54628c9a5b 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,9 @@ :LspDiag here|Jump to the next diagnostic message in the current line. :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. diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index acf073679462bd4b17bc9863ea7c98ed178bbd6e..6975edf8713936515ebba5722a83cea871078c3f 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -775,13 +775,13 @@ # 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') ? + 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,14 +797,19 @@ endif 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 diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 3dfd7ab726589eb548983d70b5e1d2d073bd3f7b..507eb00f3ec8dd69a1f1690b41cdb5baf4bc69cd 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -1161,8 +1161,8 @@ # Command-line completion for the ":LspDiag" command export def LspDiagComplete(arglead: string, cmdline: string, cursorPos: number): list 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 @@ elseif args == 'last' 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 diff --git a/doc/lsp.txt b/doc/lsp.txt index 3c1e3fc9aba83881ea6901b63c8189b80af8d463..1987bde75f540da33678e5c0d0b8b2fb127f1dff 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -88,8 +88,16 @@ :LspDiag last Jump to the last diagnostic message for the current 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 diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 9125b6eb65f5306d625eb1863b43a83058d30153..3b3815a168288fa1d5361b85cc79e69ba817b9fa 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -67,7 +67,9 @@ command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(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', ) +command! -nargs=0 -bar -count=1 LspDiagNextWrap lsp.JumpToDiag('nextWrap', ) command! -nargs=0 -bar -count=1 LspDiagPrev lsp.JumpToDiag('prev', ) +command! -nargs=0 -bar -count=1 LspDiagPrevWrap lsp.JumpToDiag('prevWrap', ) command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics() command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here') command! -nargs=0 -bar LspDocumentSymbol lsp.ShowDocSymbols()