Shougo / deoplete.nvim

:stars: Dark powered asynchronous completion framework for neovim/Vim8
Other
5.93k stars 295 forks source link

When completions are presented, C-n must be pressed twice to select keyword completion entries #1128

Closed yorickpeterse closed 4 years ago

yorickpeterse commented 4 years ago

Problems summary

I use both Deoplete and keyword completions (using C-n and C-p). When deoplete displays one or more results in a popup (but I don't select any), using C-n for completion requires pressing it twice to make a selection. Take this Python file for example:

class Foo():
    pass

class Fooo():
    pass

class Foooooo():
    pass

number = |

Here the | indicates where the cursor is. If Deoplete is enabled (and buffer completions are enabled) and I type "Fo", deoplete will show me 4 results. So far so good.

Now say that I dismiss these entries by deleting the "o", we end up with this:

number = F|

If I now press C-n, Vim will show me 3 entries but not select any of them:

Screenshot from 2020-09-10 18-18-32

To make the first selection, I have to press C-n again. This does not happen when Deoplete has no completions to show (e.g. it's disabled entirely, or all sources available have been disabled).

This can be seen in the following recording:

asciicast

Expected

Pressing C-n will always select the first entry, with or without Deoplete

Environment Information

version output ``` NVIM v0.4.4 Build type: Release LuaJIT 2.0.5 Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include Compiled by builduser Features: +acl +iconv +tui See ":help feature-compile" system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/share/nvim" Run :checkhealth for more info ```
CheckHealth output ``` health#deoplete#check ======================================================================== ## deoplete.nvim - OK: exists("v:t_list") was successful - OK: has("timers") was successful - OK: has("python3") was successful - OK: Require Python 3.6.1+ was successful - OK: Require msgpack 1.0.0+ was successful - INFO: If you're still having problems, try the following commands: - $ export NVIM_PYTHON_LOG_FILE=/tmp/log - $ export NVIM_PYTHON_LOG_LEVEL=DEBUG - $ nvim - $ cat /tmp/log_{PID} - and then create an issue on github health#nvim#check ======================================================================== ## Configuration - OK: no issues found ## Performance - OK: Build type: Release LuaJIT ## Remote Plugins - OK: Up to date ## terminal - INFO: key_backspace (kbs) terminfo entry: key_backspace=^H - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~ - INFO: $VTE_VERSION='6003' - INFO: $COLORTERM='truecolor' health#provider#check ======================================================================== ## Clipboard (optional) - OK: Clipboard tool found: xclip ## Python 2 provider (optional) - INFO: Using: g:python_host_prog = "/usr/bin/python2" - INFO: Executable: /usr/bin/python2 - ERROR: Command error (job=11, exit code 1): `'/usr/bin/python2' -c 'import sys; sys.path.remove(""); import neovim; print(neovim.__file__)'` (in '/home/yorickpeterse/Projects/general/dotfiles/dotfiles/.config/nvim/plugged/deoplete.nvim') Output: Traceback (most recent call last): File "", line 1, in ImportError: No module named neovim Stderr: Traceback (most recent call last): File "", line 1, in ImportError: No module named neovim - INFO: Python version: 2.7.18 - INFO: pynvim version: unable to load neovim Python module - ERROR: pynvim is not installed. Error: unable to load neovim Python module - ADVICE: - Run in shell: pip install pynvim ## Python 3 provider (optional) - INFO: Using: g:python3_host_prog = "/usr/bin/python" - INFO: Executable: /usr/bin/python - INFO: Python version: 3.8.5 - INFO: pynvim version: 0.4.1 - OK: Latest pynvim is installed. ## Ruby provider (optional) - INFO: Ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux] - WARNING: `neovim-ruby-host` not found. - ADVICE: - Run `gem install neovim` to ensure the neovim RubyGem is installed. - Run `gem environment` to ensure the gem bin directory is in $PATH. - If you are using rvm/rbenv/chruby, try "rehashing". - See :help |g:ruby_host_prog| for non-standard gem installations. ## Node.js provider (optional) - INFO: Node.js: v14.8.0 - WARNING: Missing "neovim" npm (or yarn) package. - ADVICE: - Run in shell: npm install -g neovim - Run in shell (if you use yarn): yarn global add neovim ```

Provide a minimal init.vim/vimrc with less than 50 lines (Required!)

let g:plug_url_format = 'git@github.com:%s.git'

call plug#begin('~/.config/nvim/plugged')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
call plug#end()

set completeopt=menu

filetype plugin indent on
syntax on

call deoplete#custom#option('ignore_sources', {
  \ '_': ['around', 'file', 'dictionary', 'tag', 'member'],
  \ })

let g:deoplete#enable_at_startup = 1

Save this file in /tmp/test.vim.

How to reproduce the problem from neovim/Vim startup (Required!)

Create /tmp/example.py with the following content:

class Foo():
    pass

class Fooo():
    pass

class Foooooo():
    pass

number =

Save this file, then start nvim as follows:

nvim -u /tmp/test.vim /tmp/example.py

Move the cursor to the end of number =, and type "Fo". Deoplete will perform buffer completion. Now delete the "o" so the popup goes away. Now press C-n, and notice how the first entry is not selected.

Next, stop NeoVim and edit /tmp/test.vim to look as follows:

let g:plug_url_format = 'git@github.com:%s.git'

call plug#begin('~/.config/nvim/plugged')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
call plug#end()

set completeopt=menu

filetype plugin indent on
syntax on

call deoplete#custom#option('ignore_sources', {
  \ '_': ['around', 'file', 'dictionary', 'tag', 'member', 'buffer'],
  \ })

let g:deoplete#enable_at_startup = 1

This will disable buffer completion. Now start NeoVim the same way as before, and again move the cursor to the end of the number = line. Type "F" and press C-n to trigger keyword completion. Note that the first entry is selected.

This problem happens consistently: whenever Deoplete has candidates to show, I have to press C-n twice to trigger keyword completion and select the first result.

Generate a logfile if appropriate

log.txt

Shougo commented 4 years ago

Sorry. This is feature of deoplete. deoplete need to disable the first entry select, because deoplete is asynchronous plugin.

set completeopt=menuone,noinsert

It may be better.

Shougo commented 4 years ago

If you don't like the behavior, you should use other auto completion plugin. No magic.

yorickpeterse commented 4 years ago

@Shougo That's unfortunate. It might be worth mentioning that somewhere in the documentation, that way it's more clear for people running into this in the future.

Shougo commented 4 years ago

OK. I have updated the documentation.

yorickpeterse commented 4 years ago

@Shougo ncm2 seems to have a similar issue, but provides a workaround/fix for this. Per https://github.com/ncm2/ncm2#install, you basically add this:

autocmd User Ncm2PopupOpen set completeopt=noinsert,menuone,noselect
autocmd User Ncm2PopupClose set completeopt=menu

I tested this and at least for ncm2 it fixes the issue. If Deoplete had a similar autocmd it invokes, that could be used as a workaround. Would adding that be a possibility?

Shougo commented 4 years ago

OK. I have implemented completeopt restore on CompleteDone. Please test deoplete latest version.

Shougo commented 4 years ago

I have reverted the change unfortunately. If I restore completeopt when CompleteDone, it breaks auto completion behavior.

Shougo commented 4 years ago

Some workaround exists.

yorickpeterse commented 4 years ago

@Shougo Thanks for taking a look at this. I'll take a look at your last two suggestions to see if I can adopt that. Thanks again!

Shougo commented 4 years ago

Example:

inoremap <expr><C-p>  pumvisible() ? "\<C-p>" : "\<C-o>:call deoplete#handler#_skip_next_completion()\<CR>\<C-p>"