aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-07 08:18:33 +0800
committerzeertzjq <zeertzjq@outlook.com>2025-03-27 07:26:42 +0800
commit90d59e6c8aa6141c54f81586df423e5a76e009f9 (patch)
tree270e4b17b890ce56f1e0763385330f6b53edebbc /test
parent30293575204bc6b1cdc8a7e06af2710921d46da2 (diff)
downloadrneovim-90d59e6c8aa6141c54f81586df423e5a76e009f9.tar.gz
rneovim-90d59e6c8aa6141c54f81586df423e5a76e009f9.tar.bz2
rneovim-90d59e6c8aa6141c54f81586df423e5a76e009f9.zip
vim-patch:9.1.1178: not possible to generate completion candidates using fuzzy matching
Problem: not possible to generate completion candidates using fuzzy matching Solution: add the 'completefuzzycollect' option for (some) ins-completion modes (glepnir) fixes vim/vim#15296 fixes vim/vim#15295 fixes vim/vim#15294 closes: vim/vim#16032 https://github.com/vim/vim/commit/f31cfa29bf72b0cdf6fa1b60346ea4e187bcafd1 Co-authored-by: glepnir <glephunter@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/functional/ui/popupmenu_spec.lua60
-rw-r--r--test/old/testdir/gen_opt_test.vim3
-rw-r--r--test/old/testdir/test_ins_complete.vim212
-rw-r--r--test/old/testdir/test_popup.vim43
4 files changed, 208 insertions, 110 deletions
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index 76673c84b8..9403f39ba1 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -6932,25 +6932,48 @@ describe('builtin popupmenu', function()
]])
feed('o<BS><C-R>=Comp()<CR>')
screen:expect_unchanged(true)
+ feed('<C-E><Esc>')
+
+ command('hi PmenuMatchSel guibg=NONE')
+ command('hi PmenuMatch guibg=NONE')
+ command('set cot=menu,noinsert,fuzzy')
+ feed('S<C-X><C-O>')
+ screen:expect(pum_start)
+ feed('fb')
+ screen:expect([[
+ fb^ |
+ {ms:f}{s:oo}{ms:B}{s:az fookind }{1: }|
+ {mn:f}{n:oo}{mn:b}{n:ar fookind }{1: }|
+ {mn:f}{n:oo}{mn:b}{n:ala fookind }{1: }|
+ {1:~ }|*15
+ {2:-- }{5:match 1 of 9} |
+ ]])
+
+ feed('<C-E><Esc>')
+ end)
+
+ it('completefuzzycollect', function()
+ exec([[
+ set completefuzzycollect=keyword,files
+ set completeopt=menu,menuone
+ ]])
- feed('<Esc>')
- command('set completeopt+=fuzzy,menu')
feed('S hello helio hero h<C-X><C-P>')
screen:expect([[
- hello helio hero h^ |
- {1:~ }{n: }{mn:h}{n:ero }{1: }|
- {1:~ }{n: }{mn:h}{n:elio }{1: }|
- {1:~ }{s: }{ms:h}{s:ello }{1: }|
+ hello helio hero hello^ |
+ {1:~ }{n: hero }{1: }|
+ {1:~ }{n: helio }{1: }|
+ {1:~ }{s: hello }{1: }|
{1:~ }|*15
{2:-- }{5:match 1 of 3} |
]])
feed('<Esc>S hello helio hero h<C-X><C-P><C-P>')
screen:expect([[
- hello helio hero h^ |
- {1:~ }{n: }{mn:h}{n:ero }{1: }|
- {1:~ }{s: }{ms:h}{s:elio }{1: }|
- {1:~ }{n: }{mn:h}{n:ello }{1: }|
+ hello helio hero helio^ |
+ {1:~ }{n: hero }{1: }|
+ {1:~ }{s: helio }{1: }|
+ {1:~ }{n: hello }{1: }|
{1:~ }|*15
{2:-- }{5:match 2 of 3} |
]])
@@ -6962,23 +6985,6 @@ describe('builtin popupmenu', function()
{2:-- }{6:Pattern not found} |
]])
feed('<C-E><Esc>')
-
- command('hi PmenuMatchSel guibg=NONE')
- command('hi PmenuMatch guibg=NONE')
- command('set cot=menu,noinsert,fuzzy')
- feed('S<C-X><C-O>')
- screen:expect(pum_start)
- feed('fb')
- screen:expect([[
- fb^ |
- {ms:f}{s:oo}{ms:B}{s:az fookind }{1: }|
- {mn:f}{n:oo}{mn:b}{n:ar fookind }{1: }|
- {mn:f}{n:oo}{mn:b}{n:ala fookind }{1: }|
- {1:~ }|*15
- {2:-- }{5:match 1 of 9} |
- ]])
-
- feed('<C-E><Esc>')
end)
-- oldtest: Test_pum_highlights_match_with_abbr()
diff --git a/test/old/testdir/gen_opt_test.vim b/test/old/testdir/gen_opt_test.vim
index aa4c5ec6e0..2127945624 100644
--- a/test/old/testdir/gen_opt_test.vim
+++ b/test/old/testdir/gen_opt_test.vim
@@ -189,6 +189,9 @@ let test_values = {
"\ 'completeopt': [['', 'menu', 'menuone', 'longest', 'preview', 'popup',
"\ " 'popuphidden', 'noinsert', 'noselect', 'fuzzy', 'preinsert', 'menu,longest'],
"\ " ['xxx', 'menu,,,longest,']],
+ \ 'completefuzzycollect': [['', 'keyword', 'files', 'whole_line',
+ \ 'keyword,whole_line', 'files,whole_line', 'keyword,files,whole_line'],
+ \ ['xxx', 'keyword,,,whole_line,']],
\ 'completeitemalign': [['abbr,kind,menu', 'menu,abbr,kind'],
\ ['', 'xxx', 'abbr', 'abbr,menu', 'abbr,menu,kind,abbr',
\ 'abbr1234,kind,menu']],
diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim
index 97a02adf0d..cd2f5d9307 100644
--- a/test/old/testdir/test_ins_complete.vim
+++ b/test/old/testdir/test_ins_complete.vim
@@ -2763,7 +2763,7 @@ func Test_completefunc_first_call_complete_add()
bwipe!
endfunc
-func Test_complete_fuzzy_match()
+func Test_complete_opt_fuzzy()
func OnPumChange()
let g:item = get(v:event, 'completed_item', {})
let g:word = get(g:item, 'word', v:null)
@@ -2819,8 +2819,66 @@ func Test_complete_fuzzy_match()
call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx')
call assert_equal('fooBaz', g:word)
- " avoid breaking default completion behavior
- set completeopt=fuzzy,menu
+ " test case for nosort option
+ set cot=menuone,menu,noinsert,fuzzy,nosort
+ " "fooBaz" should have a higher score when the leader is "fb".
+ " With "nosort", "foobar" should still be shown first in the popup menu.
+ call feedkeys("S\<C-x>\<C-o>fb", 'tx')
+ call assert_equal('foobar', g:word)
+ call feedkeys("S\<C-x>\<C-o>好", 'tx')
+ call assert_equal("你好吗", g:word)
+
+ set cot+=noselect
+ call feedkeys("S\<C-x>\<C-o>好", 'tx')
+ call assert_equal(v:null, g:word)
+ call feedkeys("S\<C-x>\<C-o>好\<C-N>", 'tx')
+ call assert_equal('你好吗', g:word)
+
+ " "nosort" shouldn't enable fuzzy filtering when "fuzzy" isn't present.
+ set cot=menuone,noinsert,nosort
+ call feedkeys("S\<C-x>\<C-o>fooB\<C-Y>", 'tx')
+ call assert_equal('fooBaz', getline('.'))
+
+ set cot=menuone,fuzzy,nosort
+ func CompAnother()
+ call complete(col('.'), [#{word: "do" }, #{word: "echo"}, #{word: "for (${1:expr1}, ${2:expr2}, ${3:expr3}) {\n\t$0\n}", abbr: "for" }, #{word: "foo"}])
+ return ''
+ endfunc
+ call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-N>\<C-N>", 'tx')
+ call assert_equal("for", g:abbr)
+ call assert_equal(2, g:selected)
+
+ set cot+=noinsert
+ call feedkeys("i\<C-R>=CompAnother()\<CR>f", 'tx')
+ call assert_equal("for", g:abbr)
+ call assert_equal(2, g:selected)
+
+ set cot=menu,menuone,noselect,fuzzy
+ call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-N>\<C-N>\<C-N>\<C-N>", 'tx')
+ call assert_equal("foo", g:word)
+ call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-P>", 'tx')
+ call assert_equal("foo", g:word)
+ call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-P>\<C-P>", 'tx')
+ call assert_equal("for", g:abbr)
+
+ " clean up
+ set omnifunc=
+ bw!
+ set complete& completeopt&
+ autocmd! AAAAA_Group
+ augroup! AAAAA_Group
+ delfunc OnPumChange
+ delfunc Omni_test
+ delfunc Comp
+ unlet g:item
+ unlet g:word
+ unlet g:abbr
+endfunc
+
+func Test_complete_fuzzy_collect()
+ new
+ redraw " need this to prevent NULL dereference in Nvim
+ set completefuzzycollect=keyword,files,whole_line
call setline(1, ['hello help hero h'])
" Use "!" flag of feedkeys() so that ex_normal_busy is not set and
" ins_compl_check_keys() is not skipped.
@@ -2852,16 +2910,6 @@ func Test_complete_fuzzy_match()
call feedkeys("A\<C-X>\<C-N>\<C-N>\<Esc>0", 'tx!')
call assert_equal('你的 我的 我的', getline('.'))
- " respect wrapscan
- set nowrapscan
- call setline(1, ["xyz", "yxz", ""])
- call cursor(3, 1)
- call feedkeys("Sy\<C-X>\<C-N>\<Esc>0", 'tx!')
- call assert_equal('y', getline('.'))
- set wrapscan
- call feedkeys("Sy\<C-X>\<C-N>\<Esc>0", 'tx!')
- call assert_equal('xyz', getline('.'))
-
" fuzzy on file
call writefile([''], 'fobar', 'D')
call writefile([''], 'foobar', 'D')
@@ -2877,7 +2925,6 @@ func Test_complete_fuzzy_match()
call assert_match('../testdir', getline('.'))
" can get completion from other buffer
- set completeopt=fuzzy,menu,menuone
vnew
call setline(1, ["completeness,", "compatibility", "Composite", "Omnipotent"])
wincmd p
@@ -2929,79 +2976,109 @@ func Test_complete_fuzzy_match()
call assert_equal('你好 他好', getline('.'))
" issue #15526
- set completeopt=fuzzy,menuone,menu,noselect
+ set completeopt=menuone,menu,noselect
call setline(1, ['Text', 'ToText', ''])
call cursor(3, 1)
call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!')
call assert_equal('Tex', getline(line('.') - 1))
- " test case for nosort option
- set cot=menuone,menu,noinsert,fuzzy,nosort
- " "fooBaz" should have a higher score when the leader is "fb".
- " With "nosort", "foobar" should still be shown first in the popup menu.
- call feedkeys("S\<C-x>\<C-o>fb", 'tx')
- call assert_equal('foobar', g:word)
- call feedkeys("S\<C-x>\<C-o>好", 'tx')
- call assert_equal("你好吗", g:word)
+ bw!
+ bw!
+ set completeopt& cfc& cpt&
+endfunc
+
+func Test_cfc_with_longest()
+ new
+ set completefuzzycollect=keyword,files,whole_line
+ set completeopt=menu,menuone,longest,fuzzy
+
+ " keyword
+ exe "normal ggdGShello helio think h\<C-X>\<C-N>\<ESC>"
+ call assert_equal("hello helio think hel", getline('.'))
+ exe "normal hello helio think h\<C-X>\<C-P>\<ESC>"
+ call assert_equal("hello helio think hel", getline('.'))
+
+ " skip non-consecutive prefixes
+ exe "normal ggdGShello helio heo\<C-X>\<C-N>\<ESC>"
+ call assert_equal("hello helio heo", getline('.'))
+
+ " kdcit
+ call writefile(['help'], 'test_keyword.txt', 'D')
+ set complete=ktest_keyword.txt
+ exe "normal ggdGSh\<C-N>\<ESC>"
+ " auto insert help when only have one match
+ call assert_equal("help", getline('.'))
+ call writefile(['hello', 'help', 'think'], 'xtest_keyword.txt', 'D')
+ set complete=kxtest_keyword.txt
+ " auto insert hel
+ exe "normal ggdGSh\<C-N>\<ESC>"
+ call assert_equal("hel", getline('.'))
+
+ " line start with a space
+ call writefile([' hello'], 'test_case1.txt', 'D')
+ set complete=ktest_case1.txt
+ exe "normal ggdGSh\<C-N>\<ESC>"
+ call assert_equal("hello", getline('.'))
- set cot+=noselect
- call feedkeys("S\<C-x>\<C-o>好", 'tx')
- call assert_equal(v:null, g:word)
- call feedkeys("S\<C-x>\<C-o>好\<C-N>", 'tx')
- call assert_equal('你好吗', g:word)
+ " multiple matches
+ set complete=ktest_case2.txt
+ call writefile([' hello help what'], 'test_case2.txt', 'D')
+ exe "normal ggdGSh\<C-N>\<C-N>\<C-N>\<C-N>\<ESC>"
+ call assert_equal("what", getline('.'))
+
+ " multiple lines of matches
+ set complete=ktest_case3.txt
+ call writefile([' hello help what', 'hola', ' hey'], 'test_case3.txt', 'D')
+ exe "normal ggdGSh\<C-N>\<C-N>\<ESC>"
+ call assert_equal("hey", getline('.'))
+ exe "normal ggdGSh\<C-N>\<C-N>\<C-N>\<C-N>\<ESC>"
+ call assert_equal("hola", getline('.'))
+
+ set complete=ktest_case4.txt
+ call writefile([' auto int enum register', 'why'], 'test_case4.txt', 'D')
+ exe "normal ggdGSe\<C-N>\<C-N>\<ESC>"
+ call assert_equal("enum", getline('.'))
+ set complete&
- " "nosort" shouldn't enable fuzzy filtering when "fuzzy" isn't present.
- set cot=menuone,noinsert,nosort
- call feedkeys("S\<C-x>\<C-o>fooB\<C-Y>", 'tx')
- call assert_equal('fooBaz', getline('.'))
+ " file
+ call writefile([''], 'hello', 'D')
+ call writefile([''], 'helio', 'D')
+ exe "normal ggdGS./h\<C-X>\<C-f>\<ESC>"
+ call assert_equal('./hel', getline('.'))
- set cot=menuone,fuzzy,nosort
- func CompAnother()
- call complete(col('.'), [#{word: "do" }, #{word: "echo"}, #{word: "for (${1:expr1}, ${2:expr2}, ${3:expr3}) {\n\t$0\n}", abbr: "for" }, #{word: "foo"}])
- return ''
- endfunc
- call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-N>\<C-N>", 'tx')
- call assert_equal("for", g:abbr)
- call assert_equal(2, g:selected)
+ " word
+ call setline(1, ['what do you think', 'why i have that', ''])
+ call cursor(3,1)
+ call feedkeys("Sw\<C-X>\<C-l>\<C-N>\<Esc>0", 'tx!')
+ call assert_equal('wh', getline('.'))
- set cot+=noinsert
- call feedkeys("i\<C-R>=CompAnother()\<CR>f", 'tx')
- call assert_equal("for", g:abbr)
- call assert_equal(2, g:selected)
+ exe "normal ggdG"
+ " auto complete when only one match
+ exe "normal Shello\<CR>h\<C-X>\<C-N>\<esc>"
+ call assert_equal('hello', getline('.'))
+ exe "normal Sh\<C-N>\<C-P>\<esc>"
+ call assert_equal('hello', getline('.'))
- set cot=menu,menuone,noselect,fuzzy
- call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-N>\<C-N>\<C-N>\<C-N>", 'tx')
- call assert_equal("foo", g:word)
- call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-P>", 'tx')
- call assert_equal("foo", g:word)
- call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-P>\<C-P>", 'tx')
- call assert_equal("for", g:abbr)
+ exe "normal Shello\<CR>h\<C-X>\<C-N>\<Esc>cch\<C-X>\<C-N>\<Esc>"
+ call assert_equal('hello', getline('.'))
+
+ " continue search for new leader after insert common prefix
+ exe "normal ohellokate\<CR>h\<C-X>\<C-N>k\<C-y>\<esc>"
+ call assert_equal('hellokate', getline('.'))
- " clean up
- set omnifunc=
- bw!
bw!
- set complete& completeopt&
- autocmd! AAAAA_Group
- augroup! AAAAA_Group
- delfunc OnPumChange
- delfunc Omni_test
- delfunc Comp
- delfunc CompAnother
- unlet g:item
- unlet g:word
- unlet g:selected
- unlet g:abbr
+ set completeopt&
+ set completefuzzycollect&
endfunc
-func Test_complete_fuzzy_with_completeslash()
+func Test_completefuzzycollect_with_completeslash()
CheckMSWindows
call writefile([''], 'fobar', 'D')
let orig_shellslash = &shellslash
set cpt&
new
- set completeopt+=fuzzy
+ set completefuzzycollect=files
set noshellslash
" Test with completeslash unset
@@ -3023,6 +3100,7 @@ func Test_complete_fuzzy_with_completeslash()
" Reset and clean up
let &shellslash = orig_shellslash
set completeslash=
+ set completefuzzycollect&
%bw!
endfunc
diff --git a/test/old/testdir/test_popup.vim b/test/old/testdir/test_popup.vim
index 51b6861e11..8f81db6213 100644
--- a/test/old/testdir/test_popup.vim
+++ b/test/old/testdir/test_popup.vim
@@ -1501,22 +1501,6 @@ func Test_pum_highlights_match()
call VerifyScreenDump(buf, 'Test_pum_highlights_09', {})
call term_sendkeys(buf, "o\<BS>\<C-R>=Comp()\<CR>")
call VerifyScreenDump(buf, 'Test_pum_highlights_09', {})
-
- " issue #15095 wrong select
- call term_sendkeys(buf, "\<ESC>:set completeopt=fuzzy,menu\<CR>")
- call TermWait(buf)
- call term_sendkeys(buf, "S hello helio hero h\<C-X>\<C-P>")
- call TermWait(buf, 50)
- call VerifyScreenDump(buf, 'Test_pum_highlights_10', {})
-
- call term_sendkeys(buf, "\<ESC>S hello helio hero h\<C-X>\<C-P>\<C-P>")
- call TermWait(buf, 50)
- call VerifyScreenDump(buf, 'Test_pum_highlights_11', {})
-
- " issue #15357
- call term_sendkeys(buf, "\<ESC>S/non_existing_folder\<C-X>\<C-F>")
- call TermWait(buf, 50)
- call VerifyScreenDump(buf, 'Test_pum_highlights_15', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
call term_sendkeys(buf, ":hi PmenuMatchSel ctermfg=14 ctermbg=NONE\<CR>")
@@ -1530,7 +1514,34 @@ func Test_pum_highlights_match()
call term_sendkeys(buf, "\<C-E>\<Esc>")
call TermWait(buf)
+ call StopVimInTerminal(buf)
+endfunc
+func Test_pum_completefuzzycollect()
+ CheckScreendump
+ let lines =<< trim END
+ set completefuzzycollect=keyword,files
+ set completeopt=menu,menuone
+ END
+ call writefile(lines, 'Xscript', 'D')
+ let buf = RunVimInTerminal('-S Xscript', {})
+
+ " issue #15095 wrong select
+ call term_sendkeys(buf, "S hello helio hero h\<C-X>\<C-P>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_01', {})
+
+ call term_sendkeys(buf, "\<ESC>S hello helio hero h\<C-X>\<C-P>\<C-P>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_02', {})
+
+ " issue #15357
+ call term_sendkeys(buf, "\<ESC>S/non_existing_folder\<C-X>\<C-F>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_03', {})
+ call term_sendkeys(buf, "\<C-E>\<Esc>")
+
+ call TermWait(buf)
call StopVimInTerminal(buf)
endfunc