comparison src/testdir/test_cmdline.vim @ 32947:306f51627f50 v9.0.1774

commit 92997dda789ad8061841128cbc99b15ec0374411 Author: Shougo Matsushita <Shougo.Matsu@gmail.com> Date: Sun Aug 20 20:55:55 2023 +0200 patch 9.0.1774: no support for custom cmdline completion Problem: no support for custom cmdline completion Solution: Add new vimscript functions Add the following two functions: - getcmdcompltype() returns custom and customlist functions - getcompletion() supports both custom and customlist closes: #12228 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 22:11:05 +0200
parents e98fc0c439aa
children 55fefd9848e3
comparison
equal deleted inserted replaced
32946:50dd2a4504d7 32947:306f51627f50
3509 \ getcompletion('TestCompletion map <bu', 'cmdline')) 3509 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3510 3510
3511 delcom TestCompletion 3511 delcom TestCompletion
3512 endfunc 3512 endfunc
3513 3513
3514 func Test_custom_completion()
3515 func CustomComplete1(lead, line, pos)
3516 return "a\nb\nc"
3517 endfunc
3518 func CustomComplete2(lead, line, pos)
3519 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3520 endfunc
3521 func Check_custom_completion()
3522 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3523 return ''
3524 endfunc
3525 func Check_customlist_completion()
3526 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3527 return ''
3528 endfunc
3529
3530 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3531 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3532
3533 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3534 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3535
3536 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3537 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3538
3539 call assert_equal(getcompletion('', 'custom,CustomComplete1'), ['a', 'b', 'c'])
3540 call assert_equal(getcompletion('', 'customlist,CustomComplete2'), ['a', 'b'])
3541 call assert_equal(getcompletion('b', 'customlist,CustomComplete2'), ['b'])
3542
3543 delcom Test1
3544 delcom Test2
3545
3546 delfunc CustomComplete1
3547 delfunc CustomComplete2
3548 delfunc Check_custom_completion
3549 delfunc Check_customlist_completion
3550 endfunc
3551
3514 " vim: shiftwidth=2 sts=2 expandtab 3552 " vim: shiftwidth=2 sts=2 expandtab