From: Andreas Louv Date: Mon, 3 Apr 2023 00:00:21 +0000 (+0200) Subject: Make it possible to provide a "[count]" for ":LspDiagNext" X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=df99d66c4826e9f7ff6b842c7c23bc59be1fa0cd;p=vim-lsp.git Make it possible to provide a "[count]" for ":LspDiagNext" This works somewhat like the count for `:h :cafter` --- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index cfca785..bdf36a4 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -457,8 +457,17 @@ export def GetDiagsByLine(lspserver: dict, bnr: number, lnum: number): list 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 @@ export def LspDiagsJump(lspserver: dict, 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, 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 diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 21423b1..fd26217 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -596,13 +596,13 @@ export def ErrorCount(): dict 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 7648257..8d2ea9d 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')