From: Yegappan Lakshmanan <4298407+yegappan@users.noreply.github.com> Date: Fri, 31 Mar 2023 01:31:23 +0000 (-0700) Subject: Merge branch 'main' into fix/convert-flaky-tsserver-test-to-clangd X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2d857517e0a9607ceee4d5ab4f445965ee540f88;p=vim-lsp.git Merge branch 'main' into fix/convert-flaky-tsserver-test-to-clangd --- 2d857517e0a9607ceee4d5ab4f445965ee540f88 diff --cc test/clangd_tests.vim index d669f5c,695d712..5800158 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@@ -272,86 -271,44 +272,123 @@@ def g:Test_LspDiag( :%bw! enddef +# Test for multiple LSP diagnostics on the same line +def g:Test_LspDiag_Multi() + :silent! edit Xtest.c + sleep 200m + + var bnr: number = bufnr() + + setline(1, [ + 'int i = "a";', + 'int j = i;', + 'int y = 0;' + ]) + :redraw! + # TODO: Waiting count doesn't include Warning, Info, and Hint diags + g:WaitForServerFileLoad(2) + :LspDiagShow + var qfl: list> = getloclist(0) + assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) + assert_equal(bnr, qfl[0].bufnr) + assert_equal(3, qfl->len()) + assert_equal([1, 5, 'W'], [qfl[0].lnum, qfl[0].col, qfl[0].type]) + assert_equal([1, 9, 'E'], [qfl[1].lnum, qfl[1].col, qfl[1].type]) + assert_equal([2, 9, 'E'], [qfl[2].lnum, qfl[2].col, qfl[2].type]) + close + + :sleep 100m + cursor(2, 1) + assert_equal('', execute('LspDiagPrev')) + assert_equal([1, 9], [line('.'), col('.')]) + + assert_equal('', execute('LspDiagPrev')) + assert_equal([1, 5], [line('.'), col('.')]) + + var output = execute('LspDiagPrev')->split("\n") + assert_equal('Error: No more diagnostics found', output[0]) + + cursor(2, 1) + assert_equal('', execute('LspDiagFirst')) + assert_equal([1, 5], [line('.'), col('.')]) + assert_equal('', execute('LspDiagNext')) + assert_equal([1, 9], [line('.'), col('.')]) + popup_clear() + + # Test for :LspDiagHere on a line with multiple diagnostics + cursor(1, 1) + :LspDiagHere + assert_equal([1, 5], [line('.'), col('.')]) + var ids = popup_list() + assert_equal(1, ids->len()) + assert_match('Incompatible pointer to integer', getbufline(ids[0]->winbufnr(), 1, '$')[0]) + popup_clear() + cursor(1, 6) + :LspDiagHere + assert_equal([1, 9], [line('.'), col('.')]) + ids = popup_list() + assert_equal(1, ids->len()) + assert_match('Initializer element is not', getbufline(ids[0]->winbufnr(), 1, '$')[0]) + popup_clear() + + # Line without diagnostics + cursor(3, 1) + output = execute('LspDiagHere')->split("\n") + assert_equal('Error: No more diagnostics found on this line', output[0]) + + g:LspOptionsSet({showDiagInPopup: false}) + for i in range(1, 5) + cursor(1, i) + output = execute('LspDiagCurrent')->split('\n') + assert_match('Incompatible pointer to integer', output[0]) + endfor + for i in range(6, 12) + cursor(1, i) + output = execute('LspDiagCurrent')->split('\n') + assert_match('Initializer element is not ', output[0]) + endfor + g:LspOptionsSet({showDiagInPopup: true}) + + bw! +enddef + + # Test for highlight diag inline + def g:Test_LspHighlightDiagInline() + :silent! edit Xtest.c + sleep 200m + setline(1, [ + 'int main()', + '{', + ' struct obj obj', + '', + ' return 1;', + '}', + ]) + + # TODO: Waiting count doesn't include Warning, Info, and Hint diags + g:WaitForDiags(2) + + var props = prop_list(1) + assert_equal(0, props->len()) + props = prop_list(2) + assert_equal(0, props->len()) + props = prop_list(3) + assert_equal(2, props->len()) + assert_equal([ + {'id': 0, 'col': 12, 'type_bufnr': 0, 'end': 1, 'type': 'LspDiagInlineInfo', 'length': 3, 'start': 1}, + {'id': 0, 'col': 16, 'type_bufnr': 0, 'end': 1, 'type': 'LspDiagInlineError', 'length': 3, 'start': 1} + ], props) + props = prop_list(4) + assert_equal(0, props->len()) + props = prop_list(5) + assert_equal(1, props->len()) + assert_equal([{'id': 0, 'col': 5, 'type_bufnr': 0, 'end': 1, 'type': 'LspDiagInlineError', 'length': 6, 'start': 1}], props) + props = prop_list(6) + assert_equal(0, props->len()) + + bw! - + enddef + # Test for :LspCodeAction def g:Test_LspCodeAction() silent! edit Xtest.c