neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.15k stars 953 forks source link

API for check if there is a slection of the completion #5063

Closed Kaiser-Yang closed 6 days ago

Kaiser-Yang commented 6 days ago

Problem

I use this command to map my <CR>:

inoremap <silent><expr> <CR>
    \ coc#pum#visible() ? coc#pum#confirm() :
    \ CopilotVisible() ? copilot#Accept() : "\<C-g>u\<CR><C-r>=AutoPairsReturn()\<cr>"

This is simple, let me explain. <CR> will confirm completion from coc if there is a completion list, when there is no coc completion visible, and try to accept the copilot suggestions.

The problem is sometimes, when I input very quickly, and I press enter, this may confirm the coc completion. So I set noselect in coc-settings.json, but I must press <CR> twice to input a new line when there is a coc completion list.

Preferred Solution

Solution can be a new api for check if there is a selection of the coc completion, may be coc#pum#has_item_selected() or something like this to check if there is one selected item in the list. With this, I can simply update my mapping command with this below (after this, I only need press <cr> once to input a new line with noselect=true):

inoremap <silent><expr> <CR>
    \ coc#pum#has_item_selected() ? coc#pum#confirm() :
    \ CopilotVisible() ? copilot#Accept() : "\<C-g>u\<CR><C-r>=AutoPairsReturn()\<cr>"

Is this possible to be implemented?

Kaiser-Yang commented 6 days ago

I am working on this, pr comming soon.