From ae512e48186442922016832784eaa1a770669051 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 26 Dec 2015 12:39:45 +0900 Subject: [PATCH] Add angle support --- autoload/neosnippet/parser.vim | 27 ++++++++++++++++++++++++--- test/functions.vim | 5 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/autoload/neosnippet/parser.vim b/autoload/neosnippet/parser.vim index 651da6b..6fa58e3 100644 --- a/autoload/neosnippet/parser.vim +++ b/autoload/neosnippet/parser.vim @@ -315,6 +315,26 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{ " Make snippet arguments let cnt = 1 let snippet = '' + + if abbr =~ '<.\+>' + " Add angle analysis + let snippet .= '<' + + let args = '' + for arg in split(substitute( + \ neosnippet#parser#_get_in_paren('<', '>', abbr), + \ '<\zs.\{-}\ze>', '', 'g'), '[^[]\zs\s*,\s*') + if args != '' + let args .= ', ' + endif + let args .= printf('${%d:#:%s}', cnt, escape(arg, '{}')) + let cnt += 1 + endfor + let snippet .= args + let snippet .= '>' + endif + + let args = '' for arg in split(substitute( \ neosnippet#parser#_get_in_paren(key, pair, abbr), \ key.'\zs.\{-}\ze'.pair, '', 'g'), '[^[]\zs\s*,\s*') @@ -323,12 +343,13 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{ continue endif - if cnt != 1 - let snippet .= ', ' + if args != '' + let args .= ', ' endif - let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}')) + let args .= printf('${%d:#:%s}', cnt, escape(arg, '{}')) let cnt += 1 endfor + let snippet .= args let snippet .= pair diff --git a/test/functions.vim b/test/functions.vim index 4515921..0d63aef 100644 --- a/test/functions.vim +++ b/test/functions.vim @@ -67,5 +67,10 @@ function! s:suite.get_completed_snippet() \ 'word' : 'foo{', 'abbr' : 'foo{piyo}', \ 'menu' : '', 'info' : '' \ }), '${1:#:piyo}}${2}') + + call s:assert.equals(neosnippet#parser#_get_completed_snippet({ + \ 'word' : 'Dictionary(', 'abbr' : 'Dictionary(foo)', + \ 'menu' : '', 'info' : '' + \ }), '<${1:#:Key}, ${2:#:Value}>${3:#:foo})${4}') endfunction