ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.46k stars 2.81k forks source link

disable up/down arrow keys to navigate the completion popup menu for youcompleteme #3474

Closed cridemichel closed 5 years ago

cridemichel commented 5 years ago

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

in my .vimrc I have this key remappings:

inoremap <expr> <Down>  pumvisible() ? "\<C-E>\<C-O>j" : "\<Down>"
inoremap <expr> <Up>    pumvisible() ? "\<C-E>\<C-O>k" : "\<Up>"
inoremap <expr> <C-E>   pumvisible() ? "\<C-E>\<C-O>j\<C-O>k" : "\<C-E>"

the logic of first two mappings is that by pressing up or down arrow keys, when the popup menu has been auto triggered by ycm, it does not walk through suggested completions but it discards the possible selections and the cursor goes up or down respectively. If I want to select a completion I just use C-N and C-P and I can accept it by pressing C-Y. The third mapping ensures that, on pressing , the possible actual selection is discarded and the popup completion menu is closed (if ycm auto pops up a completion menu and I press C-E the actual selection is discared but the popup menu is not closed). These settings are convenient for me when the popup menu is autotriggered by ycm but if it is triggered by C-N (i.e. if I use the vim built-in completion menu) it could be convenient to use arrow keys. Now it comes my question: Is there a way to detect if the popup menu is triggered by ycm?

Provide a clear description of the problem, including the following key questions:

Include steps to reproduce here.

Include description of a minimal test case, including any actual code required to reproduce the issue.

Include description of the expected behaviour.

Include description of the observed behaviour, including actual output, screenshots, etc.

Diagnostic data

Output of vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 28 2019 01:07:30) macOS version Included patches: 1-1722 Compiled by travis@Traviss-Mac.local Huge version with MacVim GUI. Features included (+) or not (-): +acl +cursorshape +job +mouse_urxvt +signs +user_commands +arabic +dialog_con_gui +jumplist +mouse_xterm +smartindent +vartabs +autocmd +diff +keymap +multi_byte -sound +vertsplit +autochdir +digraphs +lambda +multi_lang +spell +virtualedit -autoservername +dnd +langmap -mzscheme +startuptime +visual +balloon_eval -ebcdic +libcall +netbeans_intg +statusline +visualextra +balloon_eval_term +emacs_tags +linebreak +num64 -sun_workshop +viminfo +browse +eval +lispindent +odbeditor +syntax +vreplace ++builtin_terms +ex_extra +listcmds +packages +tag_binary +wildignore +byte_offset +extra_search +localmap +path_extra -tag_old_static +wildmenu +channel -farsi +lua/dyn +perl/dyn -tag_any_white +windows +cindent +file_in_path +menu +persistent_undo -tcl +writebackup +clientserver +find_in_path +mksession +postscript +termguicolors -X11 +clipboard +float +modify_fname +printer +terminal -xfontset +cmdline_compl +folding +mouse +profile +terminfo +xim +cmdline_hist -footer +mouseshape +python/dyn +termresponse -xpm +cmdline_info +fork() +mouse_dec +python3/dyn +textobjects -xsmp +comments +fullscreen -mouse_gpm +quickfix +textprop -xterm_clipboard +conceal -gettext -mouse_jsbterm +reltime +timers -xterm_save +cryptv -hangul_input +mouse_netterm +rightleft +title +cscope +iconv +mouse_sgr +ruby/dyn +toolbar +cursorbind +insert_expand -mouse_sysmouse +scrollbind +transparency system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc" defaults file: "$VIMRUNTIME/defaults.vim" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon -lm -lncurses -liconv -framework AppKit -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE

Place the output here, or a link to a gist.

Output of YcmDebugInfo

Printing YouCompleteMe debug information... -- Client logfile: /var/folders/26/9q3nft3x4xg2zbj45nzm100000gn/T/ycm_fga_n9fr.log -- Server Python interpreter: /usr/local/opt/python/bin/python3.7 -- Server Python version: 3.7.4 -- Server has Clang support compiled in: True -- Clang version: clang version 8.0.0 (tags/RELEASE_800/final) -- Extra configuration file found and loaded -- Extra configuration path: /Users/demichel/.ycm_extra_conf.py -- C-family completer debug information: -- Compilation database path: None -- Flags: ['-Wall', '-Wextra', '-resource-dir=/Users/demichel/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/8.0.0', '-isystem', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1', '-isystem', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1', '-isystem', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include', '-isystem', '/usr/local/include', '-isystem', '/Users/demichel/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/8.0.0/include', '-isystem', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include', '-isystem', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include', '-iframework', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks', '-iframework', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks', '-fspell-checking'] -- Translation unit: /Users/demichel/gitprova/hard_ellipses/mcsim_hardell.H -- Server running at: http://127.0.0.1:64128 -- Server process ID: 25108 -- Server logfiles: -- /var/folders/26/9q3nft3x4xg2zbj45nzm__100000gn/T/ycmd_64128_stdout_0kj7lpt8.log -- /var/folders/26/9q3nft3x4xg2zbj45nzm100000gn/T/ycmd_64128_stderr_9j3tph7d.log

Place the output here, or a link to a gist.

Contents of YCM, ycmd and completion engine logfiles

Add let g:ycm_log_level = 'debug' to vimrc, restart Vim, reproduce the issue, and include link here to a gist containing the entire logfiles for ycm, ycmd and any completer logfiles listed by :YcmToggleLogs.

2019-08-30 09:18:12,422 - ERROR - HTTPConnectionPool(host='127.0.0.1', port=64858): Max retries exceeded with url: /ready (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x109b7fe50>: Failed to establish a new connection: [Errno 61] Connection refused')) 2019-08-30 09:18:12,525 - ERROR - HTTPConnectionPool(host='127.0.0.1', port=64858): Max retries exceeded with url: /ready (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x109b947d0>: Failed to establish a new connection: [Errno 61] Connection refused'))

ValueError: No semantic completer exists for filetypes: ['vim'] 2019-08-30 09:18:54,132 - INFO - Received debug info request 2019-08-30 09:18:54,132 - ERROR - Error retrieving completer debug info Traceback (most recent call last): File "/Users/demichel/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/handlers.py", line 234, in DebugInfo request_data ).DebugInfo( request_data ) File "/Users/demichel/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/handlers.py", line 298, in _GetCompleterForRequestData return _server_state.GetFiletypeCompleter( request_data[ 'filetypes' ] ) File "/Users/demichel/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 100, in GetFiletypeCompleter current_filetypes ) ) ValueError: No semantic completer exists for filetypes: ['']

serving on http://localhost:64858

OS version, distribution, etc.

mac osx mojave 10.14.6

Include system information here.

Output of build/install commands

Include link to a gist containing the invocation and entire output of install.py if reporting an installation issue.

bstaletic commented 5 years ago

There is no way to know what opened the completion menu. You should take a look at :h i_CTRL-y. It will simplify the third mapping and allow you to work around the need to know "who" spawned the menu.

cridemichel commented 5 years ago

Hi Boris, it would be enough to set a suitable global variable when popup is autotriggered by youcompleteme, in principle it can be easily done. I gave a look at i_CTRL-y documentation but frankly speaking I can not see how it can help, could you elaborate a bit more?

best C.

Il giorno 30 ago 2019, alle ore 10:22, Boris Staletic notifications@github.com ha scritto:

Closed #3474 https://github.com/ycm-core/YouCompleteMe/issues/3474.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ycm-core/YouCompleteMe/issues/3474?email_source=notifications&email_token=ADU4YGTE5P7MWWF5SHBXOM3QHDKFXA5CNFSM4ISKEERKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTLA5YNI#event-2596396085, or mute the thread https://github.com/notifications/unsubscribe-auth/ADU4YGWVDZTFTFK4XRCP36DQHDKFXANCNFSM4ISKEERA.

puremourning commented 5 years ago

we don't set any variable and it seems fragile. I think this use case is sufficiently niche that it doesn't warrant the additional complexity, sorry.

cridemichel commented 5 years ago

Dear Boris, I do not know how much niche is my request….in insert mode I use arrows to move around and if popup menu has been autotriggered by ycm, I end up with picking up a selection rather than moving…it is annoying. The real point is that you can not disable the navigation with up/down arrow keys through suggested completions just for youcomplete. With other editors/IDE, such as Atom, you can easily do that. I am quite confident that this is an issue not only for me, at least many would benefit from having the possibility to disable the navigation with arrow keys in the completion menu. I changed the title of my issue to focus on the real point,

best C.

Il giorno 30 ago 2019, alle ore 11:21, Ben Jackson notifications@github.com ha scritto:

we don't set any variable and it seems fragile. I think this use case is sufficiently niche that it doesn't warrant the additional complexity, sorry.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ycm-core/YouCompleteMe/issues/3474?email_source=notifications&email_token=ADU4YGUPAKAJZJGMTQ7S5CLQHDRCZA5CNFSM4ISKEERKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5RDMRY#issuecomment-526530119, or mute the thread https://github.com/notifications/unsubscribe-auth/ADU4YGQHIUARQGGOJKV6UGDQHDRCZANCNFSM4ISKEERA.

puremourning commented 5 years ago

at least many would benefit from having the possibility to disable the navigation with arrow keys in the completion menu,

Have you looked at this and related settings ?

https://github.com/ycm-core/YouCompleteMe#the-gycm_key_list_select_completion-option

cridemichel commented 5 years ago

at least many would benefit from having the possibility to disable the navigation with arrow keys in the completion menu,

Have you looked at this and related settings ?

https://github.com/ycm-core/YouCompleteMe#the-gycm_key_list_select_completion-option

yes, indeed if you remove '' and '' from g:ycm_key_list_previous_completion and g:ycm_key_list_select_completion respectively it does not have any effect since this key mappings are built-in in vim. It is a known issue (see #1810)

puremourning commented 5 years ago

erm, then it's a Vim issue ?

don't people normally just do something like pumvisible() ? "\<C-Y>\<Down>" : "\<Down>" ?

cridemichel commented 5 years ago

no since vim allows you to circumvent it as you are suggesting and as I did. Anyway you have also been cheated by the documentation thinking that by just removing

and from g:ycm_key_list_previous_completion and g:ycm_key_list_select_completion it is enough to disable them.... > Il giorno 30 ago 2019, alle ore 11:33, Ben Jackson ha scritto: > > erm, then it's a Vim issue ? > > don't people normally just do something like pumvisible() ? "\\" : "\" ? > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub , or mute the thread . >