comparison src/testdir/test_quickfix.vim @ 20814:f23c6543a54d v8.2.0959

patch 8.2.0959: using 'quickfixtextfunc' is a bit slow Commit: https://github.com/vim/vim/commit/00e260bb6cc33ff5dbba15ac87ca7fd465aa49c0 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 11 19:35:52 2020 +0200 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 https://github.com/vim/vim/issues/6234)
author Bram Moolenaar <Bram@vim.org>
date Thu, 11 Jun 2020 19:45:03 +0200
parents 1e2e81dbb958
children 2c3e7a6bd6c6
comparison
equal deleted inserted replaced
20813:a7c491ba7e3f 20814:f23c6543a54d
4816 endfunc 4816 endfunc
4817 4817
4818 " Test for the 'quickfixtextfunc' setting 4818 " Test for the 'quickfixtextfunc' setting
4819 func Tqfexpr(info) 4819 func Tqfexpr(info)
4820 if a:info.quickfix 4820 if a:info.quickfix
4821 let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, 4821 let qfl = getqflist({'id' : a:info.id, 'items' : 1}).items
4822 \ 'items' : 1}).items
4823 else 4822 else
4824 let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'idx' : a:info.idx, 4823 let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'items' : 1}).items
4825 \ 'items' : 1}).items
4826 endif 4824 endif
4827 4825
4828 let e = qfl[0] 4826 let l = []
4829 let s = '' 4827 for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
4830 if e.bufnr != 0 4828 let e = qfl[idx]
4831 let bname = bufname(e.bufnr) 4829 let s = ''
4832 let s ..= fnamemodify(bname, ':.') 4830 if e.bufnr != 0
4833 endif 4831 let bname = bufname(e.bufnr)
4834 let s ..= '-' 4832 let s ..= fnamemodify(bname, ':.')
4835 let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-' 4833 endif
4836 let s ..= e.text 4834 let s ..= '-'
4837 4835 let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-'
4838 return s 4836 let s ..= e.text
4837 call add(l, s)
4838 endfor
4839
4840 return l
4839 endfunc 4841 endfunc
4840 4842
4841 func Xtest_qftextfunc(cchar) 4843 func Xtest_qftextfunc(cchar)
4842 call s:setup_commands(a:cchar) 4844 call s:setup_commands(a:cchar)
4843 4845
4857 set quickfixtextfunc& 4859 set quickfixtextfunc&
4858 4860
4859 " Test for per list 'quickfixtextfunc' setting 4861 " Test for per list 'quickfixtextfunc' setting
4860 func PerQfText(info) 4862 func PerQfText(info)
4861 if a:info.quickfix 4863 if a:info.quickfix
4862 let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, 4864 let qfl = getqflist({'id' : a:info.id, 'items' : 1}).items
4863 \ 'items' : 1}).items
4864 else 4865 else
4865 let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'idx' : a:info.idx, 4866 let qfl = getloclist(a:info.winid, {'id' : a:info.id, 'items' : 1}).items
4866 \ 'items' : 1}).items
4867 endif 4867 endif
4868 if empty(qfl) 4868 if empty(qfl)
4869 return '' 4869 return []
4870 endif 4870 endif
4871 return 'Line ' .. qfl[0].lnum .. ', Col ' .. qfl[0].col 4871 let l = []
4872 for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
4873 call add(l, 'Line ' .. qfl[idx].lnum .. ', Col ' .. qfl[idx].col)
4874 endfor
4875 return l
4872 endfunc 4876 endfunc
4873 set quickfixtextfunc=Tqfexpr 4877 set quickfixtextfunc=Tqfexpr
4874 call g:Xsetlist([], ' ', {'quickfixtextfunc' : "PerQfText"}) 4878 call g:Xsetlist([], ' ', {'quickfixtextfunc' : "PerQfText"})
4875 Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] 4879 Xaddexpr ['F1:10:2:green', 'F1:20:4:blue']
4876 Xwindow 4880 Xwindow
4906 endfunc 4910 endfunc
4907 set quickfixtextfunc=Xqftext 4911 set quickfixtextfunc=Xqftext
4908 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E119:') 4912 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E119:')
4909 call assert_fails("Xwindow", 'E119:') 4913 call assert_fails("Xwindow", 'E119:')
4910 Xclose 4914 Xclose
4915
4916 " set option to a function that returns a list with non-strings
4917 func Xqftext2(d)
4918 return ['one', [], 'two']
4919 endfunc
4920 set quickfixtextfunc=Xqftext2
4921 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']",
4922 \ 'E730:')
4923 call assert_fails('Xwindow', 'E730:')
4924 call assert_equal(['one', 'F1|20 col 4| blue', 'two'], getline(1, '$'))
4925 Xclose
4926
4911 set quickfixtextfunc& 4927 set quickfixtextfunc&
4912 delfunc Xqftext 4928 delfunc Xqftext
4929 delfunc Xqftext2
4913 endfunc 4930 endfunc
4914 4931
4915 func Test_qftextfunc() 4932 func Test_qftextfunc()
4916 call Xtest_qftextfunc('c') 4933 call Xtest_qftextfunc('c')
4917 call Xtest_qftextfunc('l') 4934 call Xtest_qftextfunc('l')