autoload/lsp/diag.vim | 17 ++++++++--------- test/unit_tests.vim | 6 +++--- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 4382c4a9233b44d96260aaba6003d1f50bce520a..0b412369f28bd6fe0439b1c42514dcb118026b09 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -278,11 +278,9 @@ return {} 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 @@ return 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 0c2e8680de262734c0df2875190fe90f95f89c96..8e9a47136dd63765f950053ba706a39820e05a9a 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -330,13 +330,13 @@ normal gg 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