ncm2 / ncm2-ultisnips

44 stars 3 forks source link

clangd snippet not working #17

Closed kwon-young closed 5 years ago

kwon-young commented 5 years ago

Hello, ncm2-ultisnips doesn't work well with the clangd language server for c and cpp.

First of all, all completion item will be prepend by one space. But using enter to trigger a snippet will remove the space, although the completion item is not a snippet. completion

When trying to use a snippet suggestion from clangd, the snippet will not expand after hitting \<CR> and the prepended space will not be removed. snippet

Here is a minimal reproducible vimrc:

set nocompatible
call plug#begin()
Plug 'junegunn/fzf', { 'dir': '~/.config/fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'autozimu/LanguageClient-neovim', {
      \ 'branch': 'next',
      \ 'do': 'bash install.sh'
      \ }
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'ncm2/ncm2-ultisnips'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
call plug#end()
set noswapfile
set hidden

"let g:LanguageClient_devel = 1
let g:LanguageClient_loggingLevel = 'INFO'
let g:LanguageClient_loggingFile = expand('~/.local/share/nvim/LanguageClient.log')
let g:LanguageClient_serverStderr = expand('~/.local/share/nvim/LanguageServer.log')
let g:LanguageClient_serverCommands = {
      \ 'python': ['pyls'],
      \ 'cpp': ['clangd'],
      \ 'c': ['clangd'],
      \ 'rust': ['rls'],
      \ 'typescript': ['typescript-language-server', '--stdio']
      \ }
let g:LanguageClient_autoStart = 1
set signcolumn=yes
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=noinsert,menuone,noselect
" Press enter key to trigger snippet expansion
" The parameters are the same as `:help feedkeys()`
inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<CR>", 'n')

" c-j c-k for moving in snippet
" let g:UltiSnipsExpandTrigger      = "<Plug>(ultisnips_expand)"
let g:UltiSnipsJumpForwardTrigger   = "<c-j>"
let g:UltiSnipsJumpBackwardTrigger  = "<c-k>"
let g:UltiSnipsRemoveSelectModeMappings = 0

Using:

I also checked that ncm2-snippet is working well with the rust language server rls

roxma commented 5 years ago

Cannot reproduce:

clangd

roxma commented 5 years ago

Oh, I noticed that in your first example, clangd pops up with label " bar". Note that there's a space before "bar". After you expand the snippet, you get "bar" instead of " bar". It is the right behavior for ncm2.

You could get the full contents of the completed item by :echo v:completed_item after the completion.

{'word': ' bar', 'menu': '[+] [LC] int', 'user_data': '{"snippet_word": " bar", "source": "LanguageClient_cpp", "ncm2": 1, "match_key": "abbr", "match_highlight": [[1, 3]], "snippet": "bar",
 "ultisnips_snippet": "bar", "ncm2_lspitem": {"sortText": "3f2cccccbar", "insertTextFormat": 2, "detail": "int", "filterText": "bar", "kind": 5, "insertText": "bar", "label": " bar"}, "is_sn
ippet": 1}', 'info': '', 'kind': 'Field', 'abbr': ' bar'}

I think this is a clangd quirk:

kwon-young commented 5 years ago

Thanks a lot, it now works like a charm!

cairijun commented 5 years ago

you should start clangd with -header-insertion-decorators=false, which disables the prepended spaces