diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2024-10-15 18:53:59 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-15 18:53:59 +0800 |
| commit | 84623dbe93777c0a8e7ddf57470ddeb2ea738069 (patch) | |
| tree | 0856b7556667a3efc5c7ec6219a9a5b3f47d487d /test/old/testdir/test_quickfix.vim | |
| parent | e0a5c3bb581752569df4490b48cb54e7c1ab0613 (diff) | |
| download | rneovim-84623dbe93777c0a8e7ddf57470ddeb2ea738069.tar.gz rneovim-84623dbe93777c0a8e7ddf57470ddeb2ea738069.tar.bz2 rneovim-84623dbe93777c0a8e7ddf57470ddeb2ea738069.zip | |
vim-patch:9.1.0785: cannot preserve error position when setting quickfix list (#30820)
Problem: cannot preserve error position when setting quickfix lists
Solution: Add the 'u' action for setqflist()/setloclist() and try
to keep the closes target position (Jeremy Fleischman)
fixes: vim/vim#15839
closes: vim/vim#15841
https://github.com/vim/vim/commit/27fbf6e5e8bee5c6b61819a5e82a0b50b265f0b0
Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
Diffstat (limited to 'test/old/testdir/test_quickfix.vim')
| -rw-r--r-- | test/old/testdir/test_quickfix.vim | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index b4f8b2626a..c50fef1e46 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -6340,6 +6340,97 @@ func Test_quickfix_buffer_contents() call setqflist([], 'f') endfunc +func Test_quickfix_update() + " Setup: populate a couple buffers + new + call setline(1, range(1, 5)) + let b1 = bufnr() + new + call setline(1, range(1, 3)) + let b2 = bufnr() + " Setup: set a quickfix list. + let items = [{'bufnr': b1, 'lnum': 1}, {'bufnr': b1, 'lnum': 2}, {'bufnr': b2, 'lnum': 1}, {'bufnr': b2, 'lnum': 2}] + call setqflist(items) + + " Open the quickfix list, select the third entry. + copen + exe "normal jj\<CR>" + call assert_equal(3, getqflist({'idx' : 0}).idx) + + " Update the quickfix list. Make sure the third entry is still selected. + call setqflist([], 'u', { 'items': items }) + call assert_equal(3, getqflist({'idx' : 0}).idx) + + " Update the quickfix list again, but this time with missing line number + " information. Confirm that we keep the current buffer selected. + call setqflist([{'bufnr': b1}, {'bufnr': b2}], 'u') + call assert_equal(2, getqflist({'idx' : 0}).idx) + + " Cleanup the buffers we allocated during this test. + %bwipe! + %bwipe! +endfunc + +func Test_quickfix_update_with_missing_coordinate_info() + new + call setline(1, range(1, 5)) + let b1 = bufnr() + + new + call setline(1, range(1, 3)) + let b2 = bufnr() + + new + call setline(1, range(1, 2)) + let b3 = bufnr() + + " Setup: set a quickfix list with no coordinate information at all. + call setqflist([{}, {}]) + + " Open the quickfix list, select the second entry. + copen + exe "normal j\<CR>" + call assert_equal(2, getqflist({'idx' : 0}).idx) + + " Update the quickfix list. As the previously selected entry has no + " coordinate information, we expect the first entry to now be selected. + call setqflist([{'bufnr': b1}, {'bufnr': b2}, {'bufnr': b3}], 'u') + call assert_equal(1, getqflist({'idx' : 0}).idx) + + " Select the second entry in the quickfix list. + copen + exe "normal j\<CR>" + call assert_equal(2, getqflist({'idx' : 0}).idx) + + " Update the quickfix list again. The currently selected entry does not have + " a line number, but we should keep the file selected. + call setqflist([{'bufnr': b1}, {'bufnr': b2, 'lnum': 3}, {'bufnr': b3}], 'u') + call assert_equal(2, getqflist({'idx' : 0}).idx) + + " Update the quickfix list again. The currently selected entry (bufnr=b2, lnum=3) + " is no longer present. We should pick the nearest entry. + call setqflist([{'bufnr': b1}, {'bufnr': b2, 'lnum': 1}, {'bufnr': b2, 'lnum': 4}], 'u') + call assert_equal(3, getqflist({'idx' : 0}).idx) + + " Set the quickfix list again, with a specific column number. The currently selected entry doesn't have a + " column number, but they share a line number. + call setqflist([{'bufnr': b1}, {'bufnr': b2, 'lnum': 4, 'col': 5}, {'bufnr': b2, 'lnum': 4, 'col': 6}], 'u') + call assert_equal(2, getqflist({'idx' : 0}).idx) + + " Set the quickfix list again. The currently selected column number (6) is + " no longer present. We should select the nearest column number. + call setqflist([{'bufnr': b1}, {'bufnr': b2, 'lnum': 4, 'col': 2}, {'bufnr': b2, 'lnum': 4, 'col': 4}], 'u') + call assert_equal(3, getqflist({'idx' : 0}).idx) + + " Now set the quickfix list, but without columns. We should still pick the + " same line. + call setqflist([{'bufnr': b2, 'lnum': 3}, {'bufnr': b2, 'lnum': 4}, {'bufnr': b2, 'lnum': 4}], 'u') + call assert_equal(2, getqflist({'idx' : 0}).idx) + + " Cleanup the buffers we allocated during this test. + %bwipe! +endfunc + " Test for "%b" in "errorformat" func Test_efm_format_b() call setqflist([], 'f') |