From: Andreas Louv Date: Sun, 19 Mar 2023 12:41:34 +0000 (+0100) Subject: Jump to the proper column when jumping to diagnostics X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4f5b661d1291f58b7349fee354000c808e899d65;p=vim-lsp.git Jump to the proper column when jumping to diagnostics --- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 4382c4a..0b41236 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -278,11 +278,9 @@ export def GetDiagByLine(lspserver: dict, bnr: number, lnum: number): dict< enddef # sort the diaganostics messages for a buffer by line number -def GetSortedDiagLines(lspsrv: dict, bnr: number): list - # create a list of line numbers from the diag map keys - var lnums: list = - lspsrv.diagsMap[bnr]->keys()->mapnew((_, v) => v->str2nr()) - return lnums->sort((a, b) => a - b) +def GetSortedDiagLines(lspsrv: dict, bnr: number): list> + var diags = lspsrv.diagsMap[bnr] + return diags->values()->sort((a, b) => a.range.start.line - b.range.start.line) enddef # jump to the next/previous/first diagnostic message in the current buffer @@ -299,19 +297,20 @@ export def LspDiagsJump(lspserver: dict, which: string): void endif # sort the diagnostics by line number - var sortedDiags: list = GetSortedDiagLines(lspserver, bnr) + var sortedDiags: list> = GetSortedDiagLines(lspserver, bnr) if which == 'first' - [sortedDiags[0], 1]->cursor() + setcursorcharpos(sortedDiags[0].range.start.line + 1, sortedDiags[0].range.start.character + 1) return endif # Find the entry just before the current line (binary search) var curlnum: number = line('.') - for lnum in (which == 'next') ? sortedDiags : sortedDiags->reverse() + for diag in (which == 'next') ? sortedDiags : sortedDiags->reverse() + var lnum = diag.range.start.line + 1 if (which == 'next' && lnum > curlnum) || (which == 'prev' && lnum < curlnum) - [lnum, 1]->cursor() + setcursorcharpos(diag.range.start.line + 1, diag.range.start.character + 1) return endif endfor diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 0c2e868..8e9a471 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -330,13 +330,13 @@ def Test_LspDiag() var output = execute('LspDiagCurrent')->split("\n") assert_equal('No diagnostic messages found for current line', output[0]) :LspDiagFirst - assert_equal([3, 1], [line('.'), col('.')]) + assert_equal([3, 14], [line('.'), col('.')]) output = execute('LspDiagCurrent')->split("\n") assert_equal("Expected ';' at end of declaration (fix available)", output[0]) :LspDiagNext - assert_equal([5, 1], [line('.'), col('.')]) + assert_equal([5, 2], [line('.'), col('.')]) :LspDiagNext - assert_equal([7, 1], [line('.'), col('.')]) + assert_equal([7, 2], [line('.'), col('.')]) output = execute('LspDiagNext')->split("\n") assert_equal('Error: No more diagnostics found', output[0]) :LspDiagPrev