mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
vim-patch:9.1.1933: completion: complete_match() is not useful (#36726)
Problem: completion: complete_match() Vim script function and
'isexpand' option are not that useful and confusing
(after v9.1.1341)
Solution: Remove function and option and clean up code and documentation
(Girish Palya).
complete_match() and 'isexpand' add no real functionality to Vim. They
duplicate what `strridx()` already does, yet pretend to be part of the
completion system. They have nothing to do with the completion mechanism.
* `f_complete_match()` in `insexpand.c` does not call any completion code.
It’s just a `STRNCMP()` wrapper with fluff logic.
* `'isexpand'` exists only as a proxy argument to that function.
It does nothing on its own and amounts to misuse of a new option.
The following Vim script function can be used to implement the same
functionality:
```vim
func CompleteMatch(triggers, sep=',')
let line = getline('.')->strpart(0, col('.') - 1)
let result = []
for trig in split(a:triggers, a:sep)
let idx = strridx(line, trig)
if l:idx >= 0
call add(result, [idx + 1, trig])
endif
endfor
return result
endfunc
```
related: vim/vim#16716
fixes: vim/vim#18563
closes: vim/vim#18790
cbcbff8712
Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
@@ -265,7 +265,6 @@ let test_values = {
|
||||
\ 'helplang': [['', 'de', 'de,it'], ['xxx']],
|
||||
"\ 'highlight': [['', 'e:Error'], ['xxx']],
|
||||
"\ 'imactivatekey': [['', 'S-space'], ['xxx']],
|
||||
\ 'isexpand': [['', '.,->', '/,/*,\\,'], [',,', '\\,,']],
|
||||
\ 'isfname': [['', '@', '@,48-52'], ['xxx', '@48']],
|
||||
\ 'isident': [['', '@', '@,48-52'], ['xxx', '@48']],
|
||||
\ 'iskeyword': [['', '@', '@,48-52'], ['xxx', '@48']],
|
||||
|
||||
@@ -4919,99 +4919,6 @@ func Test_nearest_cpt_option()
|
||||
delfunc PrintMenuWords
|
||||
endfunc
|
||||
|
||||
func Test_complete_match()
|
||||
set isexpand=.,/,->,abc,/*,_
|
||||
func TestComplete()
|
||||
let res = complete_match()
|
||||
if res->len() == 0
|
||||
return
|
||||
endif
|
||||
let [startcol, expandchar] = res[0]
|
||||
|
||||
if startcol >= 0
|
||||
let line = getline('.')
|
||||
|
||||
let items = []
|
||||
if expandchar == '/*'
|
||||
let items = ['/** */']
|
||||
elseif expandchar =~ '^/'
|
||||
let items = ['/*! */', '// TODO:', '// fixme:']
|
||||
elseif expandchar =~ '^\.' && startcol < 4
|
||||
let items = ['length()', 'push()', 'pop()', 'slice()']
|
||||
elseif expandchar =~ '^\.' && startcol > 4
|
||||
let items = ['map()', 'filter()', 'reduce()']
|
||||
elseif expandchar =~ '^\abc'
|
||||
let items = ['def', 'ghk']
|
||||
elseif expandchar =~ '^\->'
|
||||
let items = ['free()', 'xfree()']
|
||||
else
|
||||
let items = ['test1', 'test2', 'test3']
|
||||
endif
|
||||
|
||||
call complete(expandchar =~ '^/' ? startcol : startcol + strlen(expandchar), items)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
new
|
||||
inoremap <buffer> <F5> <cmd>call TestComplete()<CR>
|
||||
|
||||
call feedkeys("S/*\<F5>\<C-Y>", 'tx')
|
||||
call assert_equal('/** */', getline('.'))
|
||||
|
||||
call feedkeys("S/\<F5>\<C-N>\<C-Y>", 'tx')
|
||||
call assert_equal('// TODO:', getline('.'))
|
||||
|
||||
call feedkeys("Swp.\<F5>\<C-N>\<C-Y>", 'tx')
|
||||
call assert_equal('wp.push()', getline('.'))
|
||||
|
||||
call feedkeys("Swp.property.\<F5>\<C-N>\<C-Y>", 'tx')
|
||||
call assert_equal('wp.property.filter()', getline('.'))
|
||||
|
||||
call feedkeys("Sp->\<F5>\<C-N>\<C-Y>", 'tx')
|
||||
call assert_equal('p->xfree()', getline('.'))
|
||||
|
||||
call feedkeys("Swp->property.\<F5>\<C-Y>", 'tx')
|
||||
call assert_equal('wp->property.map()', getline('.'))
|
||||
|
||||
call feedkeys("Sabc\<F5>\<C-Y>", 'tx')
|
||||
call assert_equal('abcdef', getline('.'))
|
||||
|
||||
call feedkeys("S_\<F5>\<C-Y>", 'tx')
|
||||
call assert_equal('_test1', getline('.'))
|
||||
|
||||
set ise&
|
||||
call feedkeys("Sabc \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[1, 'abc']], g:result)
|
||||
|
||||
call assert_fails('call complete_match(99, 0)', 'E966:')
|
||||
call assert_fails('call complete_match(1, 99)', 'E964:')
|
||||
call assert_fails('call complete_match(1)', 'E474:')
|
||||
|
||||
set ise=你好,好
|
||||
call feedkeys("S你好 \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[1, '你好'], [4, '好']], g:result)
|
||||
|
||||
set ise=\\,,->
|
||||
call feedkeys("Sabc, \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[4, ',']], g:result)
|
||||
|
||||
set ise=\ ,=
|
||||
call feedkeys("Sif true \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[8, ' ']], g:result)
|
||||
call feedkeys("Slet a = \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[7, '=']], g:result)
|
||||
set ise={,\ ,=
|
||||
call feedkeys("Sif true \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[8, ' ']], g:result)
|
||||
call feedkeys("S{ \<ESC>:let g:result=complete_match()\<CR>", 'tx')
|
||||
call assert_equal([[1, '{']], g:result)
|
||||
|
||||
bw!
|
||||
unlet g:result
|
||||
set isexpand&
|
||||
delfunc TestComplete
|
||||
endfunc
|
||||
|
||||
func Test_register_completion()
|
||||
let @a = "completion test apple application"
|
||||
let @b = "banana behavior better best"
|
||||
|
||||
Reference in New Issue
Block a user