Improve completed snippet behavior

This commit is contained in:
Shougo Matsushita 2015-12-30 12:49:24 +09:00
parent 3e6f927854
commit 50a25a35a2
2 changed files with 23 additions and 4 deletions

View File

@ -324,10 +324,12 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{
for arg in split(substitute(
\ neosnippet#parser#_get_in_paren('<', '>', abbr),
\ '<\zs.\{-}\ze>', '', 'g'), '[^[]\zs\s*,\s*')
if args != ''
if args != '' && arg !=# '...'
let args .= ', '
endif
let args .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
let args .= printf('${%d:#:%s%s}',
\ cnt, ((args != '' && arg ==# '...') ? ', ' : ''),
\ escape(arg, '{}'))
let cnt += 1
endfor
let snippet .= args
@ -343,10 +345,12 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{
continue
endif
if args != ''
if args != '' && arg !=# '...'
let args .= ', '
endif
let args .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
let args .= printf('${%d:#:%s%s}',
\ cnt, ((args != '' && arg ==# '...') ? ', ' : ''),
\ escape(arg, '{}'))
let cnt += 1
endfor
let snippet .= args

View File

@ -58,6 +58,21 @@ function! s:suite.get_completed_snippet()
\ 'menu' : '', 'info' : ''
\ }), '${1:#:hoge}, ${2:#:piyo()})${3}')
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
\ 'word' : 'foo(', 'abbr' : 'foo(hoge[, abc])',
\ 'menu' : '', 'info' : ''
\ }), '${1:#:hoge[, abc]})${2}')
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
\ 'word' : 'foo(', 'abbr' : 'foo(...)',
\ 'menu' : '', 'info' : ''
\ }), '${1:#:...})${2}')
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, ...)',
\ 'menu' : '', 'info' : ''
\ }), '${1:#:hoge}${2:#:, ...})${3}')
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
\ 'word' : 'foo{', 'abbr' : 'foo{}',
\ 'menu' : '', 'info' : ''