From 50a25a35a2dee284b32ab71f28046de3c51f57eb Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 30 Dec 2015 12:49:24 +0900 Subject: [PATCH] Improve completed snippet behavior --- autoload/neosnippet/parser.vim | 12 ++++++++---- test/functions.vim | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/autoload/neosnippet/parser.vim b/autoload/neosnippet/parser.vim index 6fa58e3..0b58317 100644 --- a/autoload/neosnippet/parser.vim +++ b/autoload/neosnippet/parser.vim @@ -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 diff --git a/test/functions.vim b/test/functions.vim index 0d63aef..dc63e28 100644 --- a/test/functions.vim +++ b/test/functions.vim @@ -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' : ''