patch 9.1.0770: current command line completion is a bit limited
Problem: current command completion is a bit limited
Solution: Add the shellcmdline completion type and getmdcomplpat()
function (Ruslan Russkikh).
closes: #15823
Signed-off-by: Ruslan Russkikh <dvrussk@yandex.ru>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 790efaa..418dafa 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -1078,6 +1078,16 @@
endif
endfunc
+func Test_cmdline_complete_shellcmdline()
+ CheckExecutable whoami
+ command -nargs=1 -complete=shellcmdline MyCmd
+
+ call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
+ call assert_match('^".*\<whoami\>', @:)
+
+ delcommand MyCmd
+endfunc
+
func Test_cmdline_complete_bang()
CheckExecutable whoami
call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
@@ -3631,6 +3641,52 @@
endfor
endfunc
+" Test for shellcmdline command argument completion
+func Test_cmdline_complete_shellcmdline_argument()
+ command -nargs=+ -complete=shellcmdline MyCmd
+
+ set wildoptions=fuzzy
+
+ call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim test_cmdline.vim', @:)
+
+ call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim nonexistentfile', @:)
+
+ let compl1 = getcompletion('', 'file')[0]
+ let compl2 = getcompletion('', 'file')[1]
+ call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim ' .. compl1, @:)
+
+ call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
+
+ let compl = getcompletion('', 'file')[1]
+ call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
+
+ set wildoptions&
+ call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim test_cmdline.vim', @:)
+
+ call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim nonexistentfile', @:)
+
+ let compl1 = getcompletion('', 'file')[0]
+ let compl2 = getcompletion('', 'file')[1]
+ call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim ' .. compl1, @:)
+
+ call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
+
+ let compl = getcompletion('', 'file')[1]
+ call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
+
+ delcommand MyCmd
+endfunc
+
" Test for :! shell command argument completion
func Test_cmdline_complete_bang_cmd_argument()
set wildoptions=fuzzy
@@ -3642,30 +3698,32 @@
endfunc
func Call_cmd_funcs()
- return [getcmdpos(), getcmdscreenpos(), getcmdcompltype()]
+ return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
endfunc
func Test_screenpos_and_completion()
call assert_equal(0, getcmdpos())
call assert_equal(0, getcmdscreenpos())
call assert_equal('', getcmdcompltype())
+ call assert_equal('', getcmdcomplpat())
cnoremap <expr> <F2> string(Call_cmd_funcs())
call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
- call assert_equal("\"let a[6, 7, 'var']", @:)
+ call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
- call assert_equal("\"quit [6, 7, '']", @:)
+ call assert_equal("\"quit [6, 7, '', '']", @:)
call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
- call assert_equal("\"nosuchcommand [15, 16, '']", @:)
+ call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
- " Check that getcmdcompltype() doesn't interfere with cmdline completion.
+ " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
+ " cmdline completion.
let g:results = []
cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
call assert_equal([
- \ ['sign undefine', 14, 15, 'sign'],
- \ ['sign unplace', 13, 14, 'sign'],
- \ ['sign un', 8, 9, 'sign']], g:results)
+ \ ['sign undefine', 14, 15, 'sign', 'undefine'],
+ \ ['sign unplace', 13, 14, 'sign', 'unplace'],
+ \ ['sign un', 8, 9, 'sign', 'un']], g:results)
unlet g:results
cunmap <F2>