]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Jump to the proper column when jumping to diagnostics
authorAndreas Louv <andreas@louv.dk>
Sun, 19 Mar 2023 12:41:34 +0000 (13:41 +0100)
committerAndreas Louv <andreas@louv.dk>
Sun, 19 Mar 2023 12:46:26 +0000 (13:46 +0100)
autoload/lsp/diag.vim
test/unit_tests.vim

index 4382c4a9233b44d96260aaba6003d1f50bce520a..0b412369f28bd6fe0439b1c42514dcb118026b09 100644 (file)
@@ -278,11 +278,9 @@ export def GetDiagByLine(lspserver: dict<any>, bnr: number, lnum: number): dict<
 enddef
 
 # sort the diaganostics messages for a buffer by line number
-def GetSortedDiagLines(lspsrv: dict<any>, bnr: number): list<number>
-  # create a list of line numbers from the diag map keys
-  var lnums: list<number> =
-               lspsrv.diagsMap[bnr]->keys()->mapnew((_, v) => v->str2nr())
-  return lnums->sort((a, b) => a - b)
+def GetSortedDiagLines(lspsrv: dict<any>, bnr: number): list<dict<any>>
+  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<any>, which: string): void
   endif
 
   # sort the diagnostics by line number
-  var sortedDiags: list<number> = GetSortedDiagLines(lspserver, bnr)
+  var sortedDiags: list<dict<any>> = 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
index 0c2e8680de262734c0df2875190fe90f95f89c96..8e9a47136dd63765f950053ba706a39820e05a9a 100644 (file)
@@ -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