]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
When displaying the diag popup, validate the line number. Add a test for LspDiagsUpd...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 28 Oct 2022 05:04:13 +0000 (22:04 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 28 Oct 2022 05:04:13 +0000 (22:04 -0700)
autoload/lsp/diag.vim
test/unit_tests.vim

index 7be31eb7271cd4de8224f3519bb074e31d9f129c..acd64a568a3b0ef1aff9b5f8ec6f3c8fb48dc189 100644 (file)
@@ -210,6 +210,12 @@ def ShowDiagInPopup(diag: dict<any>)
   var dlnum = diag.range.start.line + 1
   var ltext = getline(dlnum)
   var dlcol = byteidx(ltext, diag.range.start.character + 1)
+
+  var lastline = line('$')
+  if dlnum > lastline
+    # The line number is outside the last line in the file.
+    dlnum = lastline
+  endif
   if dlcol < 1
     # The column is outside the last character in line.
     dlcol = ltext->len() + 1
index 5185de4e7feb19065a2122737c8f13279a10a00d..f59c6713a689ddc833783558bb424a176087640a 100644 (file)
@@ -814,6 +814,30 @@ def Test_LspTagFunc()
   delete('Xtest.c')
 enddef
 
+# Test for the LspDiagsUpdated autocmd
+def Test_LspDiagsUpdated_Autocmd()
+  g:LspAutoCmd = 0
+  autocmd_add([{event: 'User', pattern: 'LspDiagsUpdated', cmd: 'g:LspAutoCmd = g:LspAutoCmd + 1'}])
+  silent! edit Xtest.c
+  sleep 200m
+  var lines: list<string> =<< trim END
+    void aFunc(void)
+    {
+       return;
+    }
+  END
+  setline(1, lines)
+  :sleep 1
+  WaitForDiags(0)
+  setline(3, '    return:')
+  WaitForDiags(1)
+  setline(3, '    return;')
+  WaitForDiags(0)
+  :%bw!
+  autocmd_delete([{event: 'User', pattern: 'LspDiagsUpdated'}])
+  assert_equal(3, g:LspAutoCmd)
+enddef
+
 def LspRunTests()
   :set nomore
   :set debug=beep