autozimu/LanguageClient-neovim

Support neosnippet for function arguments completion

xu-cheng opened this issue ยท 25 comments

Summary

It seems that LanguageClient-neovim does not work well with neosnippet for function arguments completion.

Reproduction

  • neovim/vim version (nvim --version or vim --version):
NVIM v0.3.0-1011-gd05712fbe
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -I/tmp/neovim-20180422-21487-1xs1k7o/build/config -I/tmp/neovim-20180422-21487-1xs1k7o/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim-20180422-21487-1xs1k7o/build/src/nvim/auto -I/tmp/neovim-20180422-21487-1xs1k7o/build/include
Compiled by chengxu@Chengs-MacBook-Pro.local

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-d05712f_1/share/nvim"

Run :checkhealth for more info
  • This plugin version (git rev-parse --short HEAD): b96f442
  • This plugin's binary version (bin/languageclient --version):
languageclient 0.1.70 6e901906a6b63e074d043b59fe2d44107d5ad792
  • Minimal vimrc content.
call plug#begin('~/.local/share/nvim/plugged')

Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }
Plug 'Shougo/neosnippet.vim'
Plug 'Shougo/neosnippet-snippets'

call plug#end()

augroup filetype_rust
    autocmd!
    autocmd BufReadPost *.rs setlocal filetype=rust
augroup END

" Always draw sign column. Prevent buffer moving when adding/deleting sign.
set signcolumn=yes

let g:LanguageClient_serverCommands = {
    \ 'rust': ['rustup', 'run', 'stable', 'rls'],
    \ }
let g:LanguageClient_loggingLevel = 'DEBUG'

let g:deoplete#enable_at_startup = 1
let g:neosnippet#enable_completed_snippet = 1
let g:neosnippet#enable_snipmate_compatibility = 1
  • Language server link and version:
rls-preview 0.125.1-stable (cebf188 2018-03-19)
  • Steps to reproduce the issue from clean state
    1. Try to complete any function. For example, String::from in the rust.

Current Behavior

It will autocomplete String::from(${1:s}) with the cursor in the end of the line.

Expected Behavior

It should trigger neosnippet to expand each arguments in the function.

Kind of duplicate with #379.

I got the same problem ,Is there any solution?

@PendragonSaber I've switched to https://github.com/neoclide/coc.nvim and it seems to work a lot better (even without neosnippet)

@PendragonSaber I've switched to https://github.com/neoclide/coc.nvim and it seems to work a lot better (even without neosnippet)

I have tried it, but there are some problems with the configuration, I can't jump the code block.

It may fixes the problem.

autocmd CompleteDone * call neosnippet#complete_done()

I think LanguageClient-neovim should use userdata instead of word for snippet.

It may fixes the problem.

autocmd CompleteDone * call neosnippet#complete_done()

I think LanguageClient-neovim should use userdata instead of word for snippet.

thanks i will try it

rraks commented
autocmd CompleteDone * call neosnippet#complete_done()

After implementing this, completing class snippet becomes like this

classmethod(:call 69_snippets_expand_or_jump('classmethod',12)
)<2>

@rraks It must be reproduce-able for other people.
Please upload the minimal vimrc and the reproduce instructions.

I have added LanguageClient-neovim support in neosnippet.

It fixes #379 and #396 problems.
Please test it.

mikn commented

@Shougo is there any configuration required to make it work?

Nothing. But please use the latest version of neosnippet plugin.

@Shougo looks like it works, but I found a strange behavior. After expanding a function I got snippet in the following format:

fun1(<`1:int a`>, <`2:int b`>, <`3:int c`>)<|0|>  

I can move between 1-3 elements (function arguments) with neosnippet_expand_or_jump, but how can I get to leading <|0|>? May be related with Shougo/neosnippet.vim#451, but suggested solution doesn't works.

neosnippet

@jubnzv Please upload the minimal vimrc with the reroduce-able instructions like this issue.
I will test it later.

If not, I cannot help you.

It should be jumped to the last of neosnippet_expand_or_jump.

@Shougo Thank you for your reply. Here is minimal vimrc; this issue can be reproduced like on my screencast from previous post:

  1. Start typing function name; select deoplete suggestion
  2. Use <A-l> to navigate through function arguments. When you reach last argument, you got leading zero and the end of function.

My environment: latest versions of related vim plugins; neovim 0.3.4, cquery language server.

init.vim

call plug#begin('~/.local/share/nvim/plugged')
Plug 'https://github.com/Shougo/neosnippet.vim'
Plug 'https://github.com/Shougo/neosnippet-snippets'
Plug 'https://github.com/Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'autozimu/LanguageClient-neovim', {
  \ 'branch': 'next',
  \ 'do': 'bash install.sh',
  \ }
call plug#end()

set hidden
filetype plugin indent on
syntax enable
let g:python3_host_prog  = '/usr/bin/python3.6'

" Deoplete
let g:deoplete#enable_at_startup = 1
let g:deoplete#auto_complete_start_length = 1
let g:deoplete#enable_smart_case = 1
call deoplete#custom#source('LanguageClient',
            \ 'min_pattern_length',
            \ 2)
inoremap <expr><A-q> pumvisible() ? deoplete#mappings#close_popup() : "\<CR>"
inoremap <expr><A-j> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr><A-k> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr><A-o> deoplete#mappings#manual_complete()

" neosnippet
imap <A-l> <Plug>(neosnippet_expand_or_jump)
smap <A-l> <Plug>(neosnippet_expand_or_jump)
xmap <A-l> <Plug>(neosnippet_expand_target)
if has('conceal')
set conceallevel=2 concealcursor=niv

endif

" LanguageClient
let g:LanguageClient_loggingLevel = 'DEBUG'
let g:LanguageClient_settingsPath = '~/.config/nvim/settings.json'
let g:LanguageClient_loggingFile='/tmp/lc.log'
let g:LanguageClient_serverCommands = {
  \ 'cpp': ['/usr/local/bin/cquery', '--log-file=/tmp/cquery.log'],
  \ 'c': ['/usr/local/bin/cquery', '--log-file=/tmp/cquery.log'],
  \ }
let g:LanguageClient_rootMarkers = {
  \ 'cpp': ['compile_commands.json', 'build'],
  \ 'c': ['compile_commands.json', 'build'],
  \ }
let g:LanguageClient_autoStart = 0
let g:LanguageClient_hasSnippetSupport = 1
nnoremap <F5> :call LanguageClient_contextMenu()<CR>

@rraks

After implementing this, completing class snippet becomes like this

Confirmed. It is conflict of autocmd CompleteDone * call neosnippet#complete_done().
Please disable it.

@jubnzv Reproduced. I have fixed the problem in the latest version of neosnippet.

@autozimu I think the issue can be closed.

@rraks I have added g:neosnippet#enable_complete_done. Please use it instead.

@Shougo Thanks!

Verified. Closing.

@Shougo Shougo/neosnippet.vim@a3c6182 breaks down snippet expansion keybindings. With init.vim from #396 (comment) I can't expand selected snippet from pumvisible anymore.

saks commented

The same here, the very last commit broke everything for me either.

Please use the latest version of neosnippet.
I have fixed it.

Just verified, everything works with the latest master (Shougo/neosnippet.vim@c9b41fe).
@Shougo, thanks for the fix!