]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
feature: adding 'LspDiagThis'
authorshane.xb.qian <shane.qian@foxmail.com>
Mon, 20 Mar 2023 04:58:28 +0000 (12:58 +0800)
committershane.xb.qian <shane.qian@foxmail.com>
Fri, 24 Mar 2023 01:04:10 +0000 (09:04 +0800)
// jump to the diag msg in this/current line
// start from current column of current line

Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
README.md
autoload/lsp/diag.vim
doc/lsp.txt
plugin/lsp.vim
test/clangd_tests.vim

index 43e529c3bc9c13f24e6b204d08c46fa8dbadb95b..b65626ed1b089e123982fa270d62c5c7f8f81404 100644 (file)
--- a/README.md
+++ b/README.md
@@ -148,12 +148,13 @@ Command|Description
 -------|-----------
 :LspCodeAction|Apply the code action supplied by the language server to the diagnostic in the current line.
 :LspDiagCurrent|Display the diagnostic message for the current line
-:LspDiagFirst|Display the first diagnostic message for the current buffer
+:LspDiagFirst|Jump to the first diagnostic message for the current buffer
 :LspDiagHighlightDisable|Disable diagnostic message highlights
 :LspDiagHighlightEnable|Enable diagnostic message highlights
 :LspDiagNext|Jump to the next diagnostic message after the current position
 :LspDiagPrev|Jump to the previous diagnostic message before the current position
 :LspDiagShow|Display the diagnostics messages from the language server for the current buffer in a new location list.
+:LspDiagThis|Jump to the current diagnostic message in the current line
 :LspFold|Fold the current file
 :LspFormat|Format a range of lines in the current file using the language server. The **shiftwidth** and **expandtab** values set for the current buffer are used when format is applied.  The default range is the entire file.
 :LspGotoDeclaration|Go to the declaration of the keyword under cursor
index ebe379cf961c54ced8ee7b97bd94b9396ec307a0..559217ce6c8badca36a448ae1f5c373b240b944e 100644 (file)
@@ -350,11 +350,12 @@ export def LspDiagsJump(lspserver: dict<any>, which: string): void
   # Find the entry just before the current line (binary search)
   var curlnum: number = line('.')
   var curcol: number = charcol('.')
-  for diag in (which == 'next') ? diags : diags->copy()->reverse()
+  for diag in (which == 'next' || which == 'this') ? diags : diags->copy()->reverse()
     var lnum = diag.range.start.line + 1
     var col = diag.range.start.character + 1
-    if (which == 'next' && (lnum > curlnum ||  lnum == curlnum && col > curcol))
+    if (which == 'next' && (lnum > curlnum || lnum == curlnum && col > curcol))
          || (which == 'prev' && (lnum < curlnum || lnum == curlnum && col < curcol))
+         || (which == 'this' && (lnum == curlnum && col > curcol))
       setcursorcharpos(lnum, col)
       return
     endif
index d26b6b42ef2ca2b7aac2713c154d16f66428c83b..f1fd20935d8d9ca5f92dd00a7aa2b998185b743d 100644 (file)
@@ -84,6 +84,8 @@ The following commands are provided:
                        buffer before the current current position.
 :LspDiagShow           Display the diagnostics messages from the language
                        server for the current buffer in a location list.
+:LspDiagThis           Jump to the current diagnostic message for the current
+                       buffer in the current line (start from current column).
 :LspFold               Fold the current file
 :LspFormat             Format a range of lines in the current file using the
                        language server.  The default range is the entire file.
@@ -396,6 +398,10 @@ can map these commands to keys and make it easier to invoke them.
                        can use the Vim location list commands to browse the
                        list.
 
+                                               *:LspDiagThis*
+:LspDiagThis           Jumps to the location of the diagnostic message in
+                       the current line (start from current column).
+
                                                *:LspFold*
 :LspFold               Create folds for the current buffer.
 
@@ -765,8 +771,10 @@ the current file in a |location-list-window|.  You can use the |:LspDiagFirst|
 command to jump to the line with the first diagnostic message, the
 |:LspDiagNext| command to jump to the next nearest line with the diagnostic
 message, the |:LspDiagPrev| command to jump to the previous nearest line with
-the diagnostic message.  You can use the |:LspDiagCurrent| command to display
-the entire diagnostic message from the language server for the current line.
+the diagnostic message, the |:LspDiagThis| command to jump to the diagnostic
+message in the current line.  You can use the |:LspDiagCurrent| command to
+display the entire diagnostic message from the language server for the current
+line.
 
 By default, the lines with a diagnostic message have a sign placed on them and
 are highlighted.  You can temporarily disable them for the current Vim session
index f2f4aabad39f55595e3516f23500bfd9c06acf1b..0329114070efbfc5c24af681cafc0093001f4585 100644 (file)
@@ -85,6 +85,7 @@ command! -nargs=0 -bar LspDiagHighlightEnable lsp.DiagHighlightEnable()
 command! -nargs=0 -bar LspDiagNext lsp.JumpToDiag('next')
 command! -nargs=0 -bar LspDiagPrev lsp.JumpToDiag('prev')
 command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics()
+command! -nargs=0 -bar LspDiagThis lsp.JumpToDiag('this')
 command! -nargs=0 -bar LspFold lsp.FoldDocument()
 command! -nargs=0 -bar -range=% LspFormat lsp.TextDocFormat(<range>, <line1>, <line2>)
 command! -nargs=0 -bar LspGotoDeclaration lsp.GotoDeclaration(v:false, <q-mods>)
@@ -149,6 +150,7 @@ if has('gui_running')
   anoremenu <silent> L&sp.Diagnostics.First :LspDiagFirst<CR>
   anoremenu <silent> L&sp.Diagnostics.Next :LspDiagNext<CR>
   anoremenu <silent> L&sp.Diagnostics.Prev :LspDiagPrev<CR>
+  anoremenu <silent> L&sp.Diagnostics.This :LspDiagThis<CR>
 
   if &mousemodel =~ 'popup'
     anoremenu <silent> PopUp.L&sp.Go\ to\ Definition
index e38d2339a3a05f42c094f7c46d94570b07a47fa0..f405a860456cc559e66461529b7e5722817734bc 100644 (file)
@@ -244,6 +244,9 @@ def g:Test_LspDiag()
   assert_equal([3, 14], [line('.'), col('.')])
   output = execute('LspDiagCurrent')->split("\n")
   assert_equal("Expected ';' at end of declaration (fix available)", output[0])
+  :normal! 0
+  :LspDiagThis
+  assert_equal([3, 14], [line('.'), col('.')])
   :LspDiagNext
   assert_equal([5, 2], [line('.'), col('.')])
   :LspDiagNext