]> Sergey Matveev's repositories - vim-lsp.git/commit
Add support for hrsh7th/vim-vsnip snippets
authorGirish Palya <girishji@gmail.com>
Thu, 1 Jun 2023 09:04:43 +0000 (11:04 +0200)
committerGirish Palya <girishji@gmail.com>
Thu, 1 Jun 2023 09:04:43 +0000 (11:04 +0200)
commitf966fe88ec673dff2c51ed7274e91741bbc17f63
treef2f201ca428004756df733e388ed0a294867d669
parent60652f8fb3599512138097903528496aa549f9e5
Add support for hrsh7th/vim-vsnip snippets

Summary:

- Query vim-vsnip plugin for snippet completions and add the items
  to the completion list.
- Add a boolean flag to set vsnip completion option
- Update documentation
- Without this enhancement vsnip could only expand LSP provided
  snippets
- Inteface to vim-vsnip plugin is based on hrsh7th/cmp-vsnip

Following plugins need to be installed:

[required] hrsh7th/vim-vsnip
[required] hrsh7th/vim-vsnip-integ
[optional] rafamadriz/friendly-snippets

Options should be set as follows:

completionTextEdit: false,
snippetSupport: true,
vsnipSupport: true,
ultisnipsSupport: false,

Shortcoming:

Completion is not triggered for non-keyword characters like '#' (ex. #
before #if in C) even though vsnip is capable of such completion,
unless LSP server sets special characters as trigger characters. This
is not a major shortcoming since it will expand once a keyword
character is typed (say, #i in #if). To address this issue some code
reorganization is needed, and perhaps separation of completion
mechanism from the LSP client core.

User can define keymaps for Tab completion as follows:
(<Space> will expand the snippet)

def! g:LspCleverTab(): string
    return pumvisible() ? "\<c-n>" : vsnip#jumpable(1) ?
\ "\<Plug>(vsnip-jump-next)" : g:WhitespaceOnly() ?
\ "\<tab>" : "\<c-n>"
enddef
def! g:LspCleverSTab(): string
    return pumvisible() ? "\<c-p>" : vsnip#jumpable(-1) ?
\ "\<Plug>(vsnip-jump-prev)" : g:WhitespaceOnly() ?
\ "\<s-tab>" : "\<c-p>"
enddef
autocmd FileType java,c,cpp,python
            \| iunmap <silent> <tab>
            \| iunmap <silent> <s-tab>
            \| inoremap <expr> <tab> g:LspCleverTab()
            \| snoremap <expr> <tab> g:LspCleverTab()
            \| inoremap <expr> <S-Tab> g:LspCleverSTab()
            \| snoremap <expr> <S-Tab> g:LspCleverSTab()

M  autoload/lsp/completion.vim
M  autoload/lsp/options.vim
M  doc/lsp.txt
autoload/lsp/completion.vim
autoload/lsp/options.vim
doc/lsp.txt