Describe the bug
When completeopt contains menuone and there is only a single completion candidate, and that completion candidate is 'selected', complete_info().selected is -2.
The docs for complete_info().selected suggest that -1 is the only valid negative value.
To Reproduce
Detailed steps to reproduce the behavior:
vim --clean -S test.vim test.vimtest.vim:
function! Compl( findstart, query )
if a:findstart
return col( '.' )
endif
return [ 'test' ]
endfunction
set completeopt=menuone
set completefunc=Compl
"here
<C-x><C-u> (see that test is inserted/selected)<C-r>=string( complete_info().selected )-2 is inserted.Expected behavior
complete_inf().selected is 0
Environment (please complete the following information):
Additional context
I trapped it in the debugger, and unsurprisingly in the following:
if (ret == OK && (what_flag & CI_WHAT_SELECTED)) ret = dict_add_number(retdict, "selected", (compl_curr_match != NULL) ? compl_curr_match->cp_number - 1 : -1);
compl_curr_match->cp_number is -1. Scanning the code, this seems to suggest the current compl match is "invalid" in some way, but if I'm honest I didn't dig too deeply into it.
I'm not totally sure this is.a bug exactly, but in my use case I was writing a test and using complete_info() to confirm that the selected completion item is correct.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
hello,when I use coc.nvim and vim(8.2.1767),and set txt inoremap <expr> <cr> cimplete_info()["selected"] != "-1" ? "\<CR>" : '\<C-g>u\<CR> . If only 1 completion and I select the only one, it will insert a , but it works well more completions. I don't understand your test(step 4),can you test again?
@puremourning I use vim(patch 8.2.1987 ubuntu20.10),and I use your test.vim, complete_info().selected is -1 when 'menuone' is set and only 1 completion, would you mind test it again?