GithubHelp home page GithubHelp logo

ncm2-ultisnips's Introduction

UltiSnips integration for ncm2.

rec

Features

  • snippet completion source
  • trigger dynamic snippet of completed item, e.g. parameter expansion.

Reaurements

  • user_data found in vim8/nvim's documentation :help complete-item

Install

" based on ultisnips
Plug 'ncm2/ncm2-ultisnips'
Plug 'SirVer/ultisnips'

Vimrc Example

" 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

:help UltiSnips for more information on using UltiSnips.

API

If you need more control over the completed item's snippet expansion, you might need these two APIs to help program your key mapping.

ncm2_ultisnips#completed_is_snippet()

Checks whether the v:completed_item is also a snippet.

<Plug>(ncm2_ultisnips_expand_completed)

Use this key to expand the completed snippet.

ncm2-ultisnips's People

Contributors

roxma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ncm2-ultisnips's Issues

REQ: expand but try to jump forward also

currently, ncm2_ultisnips#_do_expand_or only try to expand snippet, but not try to jump forward. is it possible to add ?

let g:ulti_expand_or_jump_res = 0
function! <SID>ExpandOrClosePopup()
    let snippet = UltiSnips#ExpandSnippetOrJump()
    if g:ulti_expand_or_jump_res > 0
        echom snippet
        return snippet
    else
        return "\<c-y>"
    endif
endfunction

inoremap <silent><expr><CR> pumvisible() ? "<C-R>=<SID>ExpandOrClosePopup()<CR>" : "\<Cr>"

taking go/LC as example:
input key word "if" --> trigger expand -> input "tr" -> LC will popup menu and complete to true -> use tab to choose --> press Enter --> cursor will jump to if body.

currently, with ncm2/ultisnips, i have to use C-J to move explicitly.

How does parameter expansion work?

Hey there,

many thanks for this great completion framework!

I have it set up with neovim (v0.3.8) and latest ncm2, ultisnips, nvim-yarp, and ncm2-ultisnips. When I use the suggested configuration (with the commented line from the README.md), I get snippet completion, but when I hit Tab or Enter again, the cursor does not move to the next part of the snippet. Uncommenting said line makes no difference.

I will test a minimal .vimrc now, but any initial ideas?

Best wishes,
Rob

[Bug] Completion text is inserted when ncm2-ultisnips is installed

out

This happens when completion item does not include a snippet.

Completion works fine when ncm-ultisnips is not installed.

Plugins installed

Plug 'SirVer/ultisnips'
Plug 'ncm2/ncm2-ultisnips'
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'autozimu/LanguageClient-neovim', { 'branch': 'next', 'do': 'bash install.sh' }

Python parameter expansion with LanguageClient

I use ncm2 with LanguageClient-neovim for python autocompletion. But, I am unable to expand function parameters with this setup. It appears to me that LnaguageClient is not sending back any snippets for the functions. Does this require some additional setup?

Minimal init.vim

if &compatible " use Vim settings, rather than Vi
  set nocompatible
endif
filetype plugin indent on " enable file type detection and plugin and indent loading
syntax enable " enable syntax highlighting

call plug#begin('~/.local/share/nvim/plugged')
Plug 'autozimu/LanguageClient-neovim', {'branch': 'next', 'do': 'bash install.sh'} " vim client for LSP
Plug 'ncm2/ncm2' " completion engine
Plug 'ncm2/ncm2-ultisnips' " complete snippets
Plug 'roxma/nvim-yarp' " ncm2 dependency
Plug 'sirver/ultisnips' " create and use snippets
Plug 'honza/vim-snippets' " community decided snippets
call plug#end()

" LanguageClient-neovim
let g:LanguageClient_serverCommands = {
  \ 'python': ['pyls'],
  \ }
let g:LanguageClient_diagnosticsEnable = 0

" ncm2
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=menuone,noselect,noinsert
inoremap <expr> <C-j> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <C-k> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <silent> <expr> <CR> pumvisible() ? ncm2_ultisnips#expand_or("\<CR>", 'n') : "\<CR>"

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

screenshot from 2019-01-15 04-59-53

However, parameter expansion works(mostly) out of the box if I use ncm2-jedi as a source instead.

LSP function parameter expansion doesn't work

Plugin can complete function name, but it can't expand any function parameters,.
The language is go, using go-langserver as lsp.
All plugins and lsp are newest, neovim 0.4.0 on Linuxmint 19.04

I use key '(' to trigger parameter expansion.

Expected behaviour:
void foo ----------> void foo( -----------> void foo(a int, b int)

Below setting worked fine before(few months ago), but it can't work any more now.

" vim-plug {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')

" snippets
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'cjun714/vim-snippets-plus'

" lsp
Plug 'autozimu/LanguageClient-neovim', { 'branch': 'next', 'do': 'bash install.sh' }

" ncm2
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
if !has("nvim")
  Plug 'roxma/vim-hug-neovim-rpc'
endif
Plug 'ncm2/ncm2-ultisnips'

call plug#end()

" }}}

" SirVer/ultisnips {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:UltiSnipsExpandTrigger='<tab>'
let g:UltiSnipsJumpForwardTrigger='<C-f>'
let g:UltiSnipsJumpBackwardTrigger='<C-h>'

" }}}
" autozimu/LanguageClient-neovim {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> gf :call LanguageClient#textDocument_references()<CR>
nnoremap <leader> rn :call LanguageClient#textDocument_rename()<CR>

let g:LanguageClient_loadSettings = 1
let g:LanguageClient_settingsPath = expand('~/.vim/languageclient.json')

let g:LanguageClient_completionPreferTextEdit = 1 " ?
let g:LanguageClient_diagnosticsEnable = 1
let g:LanguageClient_selectionUI = 'quickfix'
let g:LanguageClient_serverCommands = {}
let g:LanguageClient_serverCommands.go = ['go-langserver']
let g:LanguageClient_serverCommands.rust = ['rls']
let g:LanguageClient_serverCommands.vue = ['vls']
let g:LanguageClient_serverCommands.javascript = ['javascript-typescript-stdio']
let g:LanguageClient_serverCommands.typescript = ['javascript-typescript-stdio']

" }}}
" ncm2/ncm2 {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufEnter *.rs,*.go,*.html,*.ts,*.js,*.css,*.vue,*.md call ncm2#enable_for_buffer()
set shortmess+=c
set completeopt=noinsert,menuone,noselect
au TextChangedI * call ncm2#auto_trigger()

inoremap <c-c> <ESC> " map C-c to trigger InsertLeave autocmd
inoremap <expr> <CR> (pumvisible() ? "\<c-y>\<cr>" : "\<CR>")
"inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
"inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

" }}}
" ncm2/ncm2-ultisnips {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" use '(' to trigger snippet expansion
inoremap <silent> <expr> ( ncm2_ultisnips#expand_or("()", 'n')

" imap <c-u> <Plug>(ultisnips_expand)
"let g:UltiSnipsExpandTrigger = "<Plug>(ultisnips_expand)"
let g:UltiSnipsJumpForwardTrigger = "<c-f>"
let g:UltiSnipsJumpBackwardTrigger  = "<c-h>"
let g:UltiSnipsRemoveSelectModeMappings = 0

" }}}

I also use settings in ncm2/ncm2#19 (comment), but it also can't work now.

Please help, thanks a lot!

vimrc example is wrong

Current vimrc example will not behave as expected.

Expected behavior

Expansions are triggered with enter key. Tab key will scroll through completion list if configured to do so.

Actual behavior

Expansions are triggered with tab key. Enter key will do nothing.

Fix

In the current example one line is commented out. This needs to be activated to work.

UltiSnips LSP function snippets not working

Hi!

I have a setup that uses the Tab key for both expanding snippets and jumping:

let g:UltiSnipsExpandTrigger       = "<Tab>"
let g:UltiSnipsJumpForwardTrigger  = "<Tab>"
let g:UltiSnipsJumpBackwardTrigger = "<S-Tab>"

function! MappingITab()
  let snippet = UltiSnips#ExpandSnippetOrJump()
  if g:ulti_expand_or_jump_res > 0
    return snippet
  elseif pumvisible()
    return "\<C-Y>"
  else
    return "\<Tab>"
  endif
endfunction

inoremap <silent> <expr> <Tab> MappingITab()

With ncm this works well; with ncm2 however it doesn't perform snippet expansion on LSP function completions for some reason. Expanding UltiSnips snippets (both short ones like if which don't trigger the completion yet, and long ones which do) and jumping around them works fine. Expanding LSP functions with

inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<CR>", 'n')

works fine too, but if I use Tab here it doesn't work for both expanding and jumping, and also it doesn't expand short UltiSnips snippets (which don't trigger the completion menu), so it's not optimal.

Show all UltiSnips completion

With NCM I could trigger cm_refresh to show available completions at current cursor position and all available snippets would be listed.

Is this possible with NCM2?

Thanks!

Deletion of lspitem field prevents autoimport from working

I find that when using:

  • ncm2/ncm2
  • ncm2/ncm2-ultisnips
  • autozimu/LanguageClient-neovim
  • any LSP backend that provides autoimport, e.g., pyright

The ncm2 popup menu tells me that I can autoimport with some entry, but the autoimport action is never completed. After doing some digging, I found that the problem comes from here:

Since the lspitem field is removed from user_data, LangaugeClient-neovim does not know to perform the text edit corresponding to the autoimport.

I find that removing ncm2-ultisnips, or commenting out this line, fixes the problem.

I understand that this is probably here to prevent some kind of interference between LanguageClient-neovim and ultisnips, but is there another workaround that doesn't involve disabling autoimport?

List normal snippets as well

Would be nice if this plugin could also act as a normal source to ncm2 for listing available snippets (not the ones from the language server).

clangd snippet not working

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:

  • neovim 0.3.4
  • LanguageClient-neovim 0.1.134 on branch next
  • latest ncm2, ncm2-ultisnips
  • clangd 7.0.1

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

Typescript parameter expension supported?

So I tested this with Python and with Typescript.
Python works but the typescript does not, am I missing something or is this not supported/bug.

I am on Nvim tho, maybe that got something to do with it?
below my relevant part init.vim

Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'

Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'
Plug 'ncm2/ncm2-ultisnips'
Plug 'SirVer/ultisnips'

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'

Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'mhartington/oceanic-next'
Plug 'w0rp/ale'
Plug 'ncm2/ncm2-jedi'

Plug 'mhartington/nvim-typescript', {'do': './install.sh'}
Plug 'HerringtonDarkholme/yats.vim'

inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<CR>", 'n')
let g:UltiSnipsJumpForwardTrigger	= "<c-j>"
let g:UltiSnipsJumpBackwardTrigger	= "<c-k>"
let g:UltiSnipsRemoveSelectModeMappings = 0

if it is be supported Ill will provide a specific use case to demonstrate my issue.

Function parameter expansion not working?

Hello!

Many thanks for creating this wonderful set of plugins. I'm sure this is user error, but I can't seem to get function parameter expansion to work as you have in the gif in README.md. Below is the relevant section in my init.vim and I was hoping you could help me understand where I've gone wrong!

In other words, not an issue, but a request for help (and possibly a place to add to documentation).

" Completion
  Plug 'ncm2/ncm2'
  Plug 'roxma/nvim-yarp'

  Plug 'ncm2/ncm2-tmux'
  Plug 'ncm2/ncm2-bufword'
  Plug 'ncm2/ncm2-path'
  Plug 'ncm2/ncm2-syntax'
  Plug 'ncm2/ncm2-neoinclude'
  Plug 'ncm2/ncm2-vim'
  Plug 'ncm2/ncm2-go'
  Plug 'ncm2/ncm2-jedi'
  Plug 'ncm2/ncm2-tern'
  Plug 'ncm2/ncm2-pyclang'
  Plug 'ncm2/ncm2-ultisnips'
  Plug 'SirVer/ultisnips'

  " Snippets are separated from the engine. Add this if you want them:
  Plug 'honza/vim-snippets'

  " enable ncm2 for all buffers
  autocmd BufEnter * call ncm2#enable_for_buffer()

  " :help Ncm2PopupOpen for more information
  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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.