autoload/lsp/diag.vim | 35 +++++++++++++++++++++++++---------- autoload/lsp/lsp.vim | 4 ++-- plugin/lsp.vim | 2 +- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index cfca785a3f09a72f2063d21df547f104a9d629a9..bdf36a4223e275d123972b3a81fb6bd2ce224ac3 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -457,8 +457,17 @@ endif return [] enddef +# Utility function to do the actual jump +def JumpDiag(diag: dict) + 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, which: string): void +export def LspDiagsJump(lspserver: dict, which: string, a_count: number = 0): void var fname: string = expand('%:p') if fname == '' return @@ -474,15 +483,12 @@ 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,14 +499,23 @@ if (which == 'next' && (lnum > curlnum || lnum == curlnum && col > curcol)) || (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') diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 21423b19b7847aecc64f3066872a7886d9604f03..fd26217d8ad6539e12cc4357151aeaf1b60375dd 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -596,13 +596,13 @@ return diag.DiagsGetErrorCount(lspserver) 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 = 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 diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 7648257b78851ca1a2e29dda969312cdf1250d33..8d2ea9d9bbd4a510d324312882938e09356f2f0d 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -82,7 +82,7 @@ command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(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', ) command! -nargs=0 -bar LspDiagPrev lsp.JumpToDiag('prev') command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics() command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here')