autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

Fuzzy completion #607

Open mortang2410 opened 6 years ago

mortang2410 commented 6 years ago

I use deoplete for completion. It has fuzzy search. But the suggestions from the LanguageClient source somehow don't work with fuzzy search. Everything else works with fuzzy search, including neco-vim. Is there a switch in LanguageClient somewhere to activate fuzzy search? If not, is this a bug or just not implemented yet? I'm using the latest vim from git with support for python3, lua, perl etc.

autozimu commented 6 years ago

Could you follow issue template to provide reproduction steps?

autozimu commented 6 years ago

Are you talking about this fuzzy matcher? https://github.com/Shougo/deoplete.nvim/blob/93f6e3bce8229557b952dcad792786b1cc228991/doc/deoplete.txt#L706

LanguageClient only passes on completion items from language server. If the server doesn't provide fuzzy items, then there won't be fuzzy completion.

mortang2410 commented 6 years ago

Yes, that is the matcher I was referring to. languageclient, deoplete, vim are all up-to-date from git. I have tested with minimal vimrc as wells.

Upon further testing, things seem stranger than I first thought:

So I was mistaken about LanguageClient not allowing fuzzy completion, There is just something about the link between pyls and LanguageClient. There is completion but not fuzzy completion.

My settings for deoplete and LanguageClient are as follows:

" setup deoplete
call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy'])
call deoplete#custom#option({
            \'ignore_case': v:true,
            \'complete_method':"omnifunc"
            \})

let g:deoplete#enable_at_startup = 1

"set up LanguageClient
let g:LanguageClient_serverCommands = {'python': ['pyls'], 'cpp':['ccls']}
set completefunc=LanguageClient#complete
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
set formatexpr=LanguageClient#textDocument_rangeFormatting_sync()

P.S. : I have started playing around with vim + ncm2 + LanguageClient, using ncm2's newest matcher (substrfuzzy), which is not yet documented, and not exactly full fuzzy like deoplete. But ncm2's partially fuzzy search does work with both pyls and ccls. So now I'm suspecting deoplete too. Geez. For reference, my ncm2 setup is


" "setup ncm
set shortmess+=c
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
let g:ncm2#matcher="substrfuzzy"

with LanguageClient configured the same as above. So I don't know which plugin is exactly at fault here, deoplete, LanguageClient, pyls or just my ignorant self. Maybe @Shougo would know better.

mortang2410 commented 6 years ago

Environment

1) vim :version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 14 2018 16:37:18)
Included patches: 1-390
Compiled by wilder@wilder-HP-ZBook-17
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +cmdline_compl     +emacs_tags        +insert_expand     +modify_fname      +netbeans_intg     +ruby              +terminfo          +wildignore
+arabic            +cmdline_hist      +eval              +job               +mouse             +num64             +scrollbind        +termresponse      +wildmenu
+autocmd           +cmdline_info      +ex_extra          +jumplist          +mouseshape        +packages          +signs             +textobjects       +windows
+autochdir         +comments          +extra_search      +keymap            +mouse_dec         +path_extra        +smartindent       +timers            +writebackup
-autoservername    +conceal           +farsi             +lambda            +mouse_gpm         +perl              +startuptime       +title             +X11
+balloon_eval      +cryptv            +file_in_path      +langmap           -mouse_jsbterm     +persistent_undo   +statusline        +toolbar           -xfontset
+balloon_eval_term +cscope            +find_in_path      +libcall           +mouse_netterm     +postscript        -sun_workshop      +user_commands     +xim
+browse            +cursorbind        +float             +linebreak         +mouse_sgr         +printer           +syntax            +vartabs           +xpm
++builtin_terms    +cursorshape       +folding           +lispindent        -mouse_sysmouse    +profile           +tag_binary        +vertsplit         +xsmp_interact
+byte_offset       +dialog_con_gui    -footer            +listcmds          +mouse_urxvt       +python/dyn        +tag_old_static    +virtualedit       +xterm_clipboard
+channel           +diff              +fork()            +localmap          +mouse_xterm       +python3/dyn       -tag_any_white     +visual            -xterm_save
+cindent           +digraphs          +gettext           +lua               +multi_byte        +quickfix          -tcl               +visualextra
+clientserver      +dnd               -hangul_input      +menu              +multi_lang        +reltime           +termguicolors     +viminfo
+clipboard         -ebcdic            +iconv             +mksession         -mzscheme          +rightleft         +terminal          +vreplace
   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: "/usr/local/share/vim"
 f-b for $VIMRUNTIME: "/usr/local/share/vim/vim81"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/li
b/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/
usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixb
uf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include   -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E   -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lp
angocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselin
ux   -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.26/CORE -lperl -ldl -lm -lpthread -lcrypt    -lrub
y-2.5 -lpthread -lgmp -ldl -lcrypt -lm

2) For LanguageClient-neovim: git rev-parse --short HEAD ---> 183fbf5 ./bin/languageclient --version ---> languageclient 0.1.120 For pyls: pip show python-language-server --->


Name: python-language-server
Version: 0.21.2
Summary: Python Language Server for the Language Server Protocol
Home-page: https://github.com/palantir/python-language-server
Author: Palantir Technologies, Inc.
Author-email: None
License: UNKNOWN
Location: /home/wilder/.local/lib/python3.6/site-packages
Requires: future, jedi, pluggy, python-jsonrpc-server
Required-by: pyls-mypy, pyls-isort, pyls-black

How to reproduce

1) Use this minimal .vimrc


" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }
"-------------------
if has('nvim')
    Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
    Plug 'Shougo/deoplete.nvim'
    Plug 'roxma/nvim-yarp'
    Plug 'roxma/vim-hug-neovim-rpc'
endif
Plug 'Shougo/neco-vim'
Plug 'zchee/deoplete-zsh'
"--------------------
call plug#end()

" "============
"set up LanguageClient
let g:LanguageClient_serverCommands = {'python': ['pyls'], 'cpp':['ccls']}
set omnifunc=LanguageClient#complete
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
set formatexpr=LanguageClient#textDocument_rangeFormatting_sync()

" setup deoplete
call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy'])
call deoplete#custom#option({
            \'ignore_case': v:true,
            \})
let g:deoplete#enable_at_startup = 1

 filetype plugin on

packloadall
silent! helptags ALL
set hidden
if &cp | set nocp | endif
" vim: set ft=vim :

2) Do :PlugInstall and make sure pyls is fully installed by pip install 'python-language-server[all]'. Make sure that the script pyls is in $PATH.

3) Write a sample python script in vim :e test.py

import sys
sys.p

screenshot At this point the autocompletion menu will pop up. We expect to type h and get path_hooks. But it doesn't work.

lkhphuc commented 5 years ago

Can confirm. I'm currently using both Language Client and deoplete-jedi source for deoplete. Initially the completion list contains duplicate entries from both LC and jedi, but then it only show the fuzzy match from jedi, not LC.