From: Nick Jensen Date: Mon, 18 Mar 2024 22:03:23 +0000 (+1300) Subject: Add LspDiag nextWrap and prevWrap command args X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4790c61dedecaacde9e66777279c2e68e7fd29d8;p=vim-lsp.git Add LspDiag nextWrap and prevWrap command args --- diff --git a/README.md b/README.md index 011bfe2..ba2f481 100644 --- 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. diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index acf0736..6975edf 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -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 diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 3dfd7ab..507eb00 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -1161,8 +1161,8 @@ enddef 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 @@ 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 diff --git a/doc/lsp.txt b/doc/lsp.txt index 3c1e3fc..1987bde 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -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 diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 9125b6e..3b3815a 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()