From ebe1a08366d71ab33b8b94239227d8105c43543e Mon Sep 17 00:00:00 2001 From: kevinhwang91 Date: Tue, 4 May 2021 00:05:45 +0800 Subject: vim-patch:8.2.0869: it is not possible to customize the quickfix window contents Problem: It is not possible to customize the quickfix window contents. Solution: Add 'quickfixtextfunc'. (Yegappan Lakshmanan, closes vim/vim#5465) https://github.com/vim/vim/commit/858ba06d5f577b187da0367b231f7fa9461cb32d --- src/nvim/testdir/test_quickfix.vim | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) (limited to 'src/nvim/testdir/test_quickfix.vim') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index da949f5940..3ba4e9caab 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -4786,4 +4786,124 @@ func Test_qfbuf_update() call Xqfbuf_update('l') endfunc +" Test for getting a specific item from a quickfix list +func Xtest_getqflist_by_idx(cchar) + call s:setup_commands(a:cchar) + " Empty list + call assert_equal([], g:Xgetlist({'idx' : 1, 'items' : 0}).items) + Xexpr ['F1:10:L10', 'F1:20:L20'] + let l = g:Xgetlist({'idx' : 2, 'items' : 0}).items + call assert_equal(bufnr('F1'), l[0].bufnr) + call assert_equal(20, l[0].lnum) + call assert_equal('L20', l[0].text) + call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) + call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) + %bwipe! +endfunc + +func Test_getqflist_by_idx() + call Xtest_getqflist_by_idx('c') + call Xtest_getqflist_by_idx('l') +endfunc + +" Test for the 'quickfixtextfunc' setting +func Tqfexpr(info) + if a:info.quickfix + let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, + \ 'items' : 1}).items + else + let qfl = getloclist(0, {'id' : a:info.id, 'idx' : a:info.idx, + \ 'items' : 1}).items + endif + + let e = qfl[0] + let s = '' + if e.bufnr != 0 + let bname = bufname(e.bufnr) + let s ..= fnamemodify(bname, ':.') + endif + let s ..= '-' + let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-' + let s ..= e.text + + return s +endfunc + +func Xtest_qftextfunc(cchar) + call s:setup_commands(a:cchar) + + set efm=%f:%l:%c:%m + set quickfixtextfunc=Tqfexpr + Xexpr ['F1:10:2:green', 'F1:20:4:blue'] + Xwindow + call assert_equal('F1-L10C2-green', getline(1)) + call assert_equal('F1-L20C4-blue', getline(2)) + Xclose + set quickfixtextfunc&vim + Xwindow + call assert_equal('F1|10 col 2| green', getline(1)) + call assert_equal('F1|20 col 4| blue', getline(2)) + Xclose + set efm& + set quickfixtextfunc& + + " Test for per list 'quickfixtextfunc' setting + func PerQfText(info) + if a:info.quickfix + let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, + \ 'items' : 1}).items + else + let qfl = getloclist(0, {'id' : a:info.id, 'idx' : a:info.idx, + \ 'items' : 1}).items + endif + if empty(qfl) + return '' + endif + return 'Line ' .. qfl[0].lnum .. ', Col ' .. qfl[0].col + endfunc + set quickfixtextfunc=Tqfexpr + call g:Xsetlist([], ' ', {'quickfixtextfunc' : "PerQfText"}) + Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] + Xwindow + call assert_equal('Line 10, Col 2', getline(1)) + call assert_equal('Line 20, Col 4', getline(2)) + Xclose + call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''}) + set quickfixtextfunc& + delfunc PerQfText + + " Non-existing function + set quickfixtextfunc=Tabc + " call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E117:') + Xexpr ['F1:10:2:green', 'F1:20:4:blue']" + call assert_fails("Xwindow", 'E117:') + Xclose + set quickfixtextfunc& + + " set option to a non-function + set quickfixtextfunc=[10,\ 20] + " call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E117:') + Xexpr ['F1:10:2:green', 'F1:20:4:blue']" + call assert_fails("Xwindow", 'E117:') + Xclose + set quickfixtextfunc& + + " set option to a function with different set of arguments + func Xqftext(a, b, c) + return a:a .. a:b .. a:c + endfunc + set quickfixtextfunc=Xqftext + " call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E119:') + Xexpr ['F1:10:2:green', 'F1:20:4:blue']" + call assert_fails("Xwindow", 'E119:') + Xclose + set quickfixtextfunc& + delfunc Xqftext +endfunc + +func Test_qftextfunc() + call Xtest_qftextfunc('c') + call Xtest_qftextfunc('l') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 00246d7be550cf990dac7e49903519f5dd68e89c Mon Sep 17 00:00:00 2001 From: kevinhwang91 Date: Tue, 4 May 2021 13:55:38 +0800 Subject: vim-patch:8.2.0933: 'quickfixtextfunc' does not get window ID of location list Problem: 'quickfixtextfunc' does not get window ID of location list. Solution: Add "winid" to the dict argument. (Yegappan Lakshmanan, closes vim/vim#6222) https://github.com/vim/vim/commit/7ba5a7eff335dcce25afaa154f32eeadb6014b61 --- src/nvim/testdir/test_quickfix.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir/test_quickfix.vim') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 3ba4e9caab..ed83a96906 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -4812,7 +4812,7 @@ func Tqfexpr(info) let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, \ 'items' : 1}).items else - let qfl = getloclist(0, {'id' : a:info.id, 'idx' : a:info.idx, + let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'idx' : a:info.idx, \ 'items' : 1}).items endif @@ -4853,7 +4853,7 @@ func Xtest_qftextfunc(cchar) let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, \ 'items' : 1}).items else - let qfl = getloclist(0, {'id' : a:info.id, 'idx' : a:info.idx, + let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'idx' : a:info.idx, \ 'items' : 1}).items endif if empty(qfl) @@ -4868,6 +4868,11 @@ func Xtest_qftextfunc(cchar) call assert_equal('Line 10, Col 2', getline(1)) call assert_equal('Line 20, Col 4', getline(2)) Xclose + " Add entries to the list when the quickfix buffer is hidden + Xaddexpr ['F1:30:6:red'] + Xwindow + call assert_equal('Line 30, Col 6', getline(3)) + Xclose call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''}) set quickfixtextfunc& delfunc PerQfText -- cgit From 19d4926f5a4390b4d96ea1638cc08e7798e625e2 Mon Sep 17 00:00:00 2001 From: kevinhwang91 Date: Tue, 4 May 2021 13:57:00 +0800 Subject: vim-patch:8.2.0959: using 'quickfixtextfunc' is a bit slow Problem: Using 'quickfixtextfunc' is a bit slow. Solution: Process a list of entries. (Yegappan Lakshmanan, closes vim/vim#6234) https://github.com/vim/vim/commit/00e260bb6cc33ff5dbba15ac87ca7fd465aa49c0 --- src/nvim/testdir/test_quickfix.vim | 59 +++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'src/nvim/testdir/test_quickfix.vim') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index ed83a96906..06a0fd5001 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -4809,24 +4809,27 @@ endfunc " Test for the 'quickfixtextfunc' setting func Tqfexpr(info) if a:info.quickfix - let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, - \ 'items' : 1}).items + let qfl = getqflist({'id' : a:info.id, 'items' : 1}).items else - let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'idx' : a:info.idx, - \ 'items' : 1}).items + let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'items' : 1}).items endif - let e = qfl[0] - let s = '' - if e.bufnr != 0 - let bname = bufname(e.bufnr) - let s ..= fnamemodify(bname, ':.') - endif - let s ..= '-' - let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-' - let s ..= e.text - return s + let l = [] + for idx in range(a:info.start_idx - 1, a:info.end_idx - 1) + let e = qfl[idx] + let s = '' + if e.bufnr != 0 + let bname = bufname(e.bufnr) + let s ..= fnamemodify(bname, ':.') + endif + let s ..= '-' + let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-' + let s ..= e.text + call add(l, s) + endfor + + return l endfunc func Xtest_qftextfunc(cchar) @@ -4850,16 +4853,18 @@ func Xtest_qftextfunc(cchar) " Test for per list 'quickfixtextfunc' setting func PerQfText(info) if a:info.quickfix - let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, - \ 'items' : 1}).items + let qfl = getqflist({'id' : a:info.id, 'items' : 1}).items else - let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'idx' : a:info.idx, - \ 'items' : 1}).items + let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'items' : 1}).items endif if empty(qfl) - return '' + return [] endif - return 'Line ' .. qfl[0].lnum .. ', Col ' .. qfl[0].col + let l = [] + for idx in range(a:info.start_idx - 1, a:info.end_idx - 1) + call add(l, 'Line ' .. qfl[idx].lnum .. ', Col ' .. qfl[idx].col) + endfor + return l endfunc set quickfixtextfunc=Tqfexpr call g:Xsetlist([], ' ', {'quickfixtextfunc' : "PerQfText"}) @@ -4902,8 +4907,22 @@ func Xtest_qftextfunc(cchar) Xexpr ['F1:10:2:green', 'F1:20:4:blue']" call assert_fails("Xwindow", 'E119:') Xclose + + " set option to a function that returns a list with non-strings + func Xqftext2(d) + return ['one', [], 'two'] + endfunc + set quickfixtextfunc=Xqftext2 + " call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']", + " \ 'E730:') + Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red'] + call assert_fails('Xwindow', 'E730:') + call assert_equal(['one', 'F1|20 col 4| blue', 'two'], getline(1, '$')) + Xclose + set quickfixtextfunc& delfunc Xqftext + delfunc Xqftext2 endfunc func Test_qftextfunc() -- cgit