[vim/vim] complete_info().selected is -2 when 'menuone' is set and only 1 completion (#6945)

22 views
Skip to first unread message

Ben Jackson

unread,
Sep 12, 2020, 3:11:02 PM9/12/20
to vim/vim, Subscribed

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:

  1. Run vim --clean -S test.vim test.vim

test.vim:

function! Compl( findstart, query )
  if a:findstart
    return col( '.' )
  endif
  return [ 'test' ]
endfunction

set completeopt=menuone
set completefunc=Compl

"here
  1. Go to the end of the file
  2. Type <C-x><C-u> (see that test is inserted/selected)
  3. Remaining in insert mode, type <C-r>=string( complete_info().selected )
  4. Observe that -2 is inserted.

Expected behavior

complete_inf().selected is 0

Environment (please complete the following information):

  • Vim version 8.2.1456
  • OS: macOS 10.15
  • Terminal: iTerm2

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.

Bram Moolenaar

unread,
Sep 12, 2020, 4:53:54 PM9/12/20
to vim/vim, Subscribed

Closed #6945 via b806aa5.

csh

unread,
Oct 21, 2020, 5:22:41 AM10/21/20
to vim/vim, Subscribed

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?

csh

unread,
Oct 25, 2020, 9:25:12 PM10/25/20
to vim/vim, Subscribed

@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?

puremo...@gmail.com

unread,
Oct 26, 2020, 7:25:03 AM10/26/20
to vim_dev
I get the same behaviour. we get `-1` when it should be `0`.

The original report was that it would return `-2` which was invalid by the spec. `-1` is just incorrect I think.

Reply all
Reply to author
Forward
0 new messages