Add angle support

This commit is contained in:
Shougo Matsushita 2015-12-26 12:39:45 +09:00
parent 0b3b441bef
commit ae512e4818
2 changed files with 29 additions and 3 deletions

View File

@ -315,6 +315,26 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{
" Make snippet arguments " Make snippet arguments
let cnt = 1 let cnt = 1
let snippet = '' 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( for arg in split(substitute(
\ neosnippet#parser#_get_in_paren(key, pair, abbr), \ neosnippet#parser#_get_in_paren(key, pair, abbr),
\ key.'\zs.\{-}\ze'.pair, '', 'g'), '[^[]\zs\s*,\s*') \ key.'\zs.\{-}\ze'.pair, '', 'g'), '[^[]\zs\s*,\s*')
@ -323,12 +343,13 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{
continue continue
endif endif
if cnt != 1 if args != ''
let snippet .= ', ' let args .= ', '
endif endif
let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}')) let args .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
let cnt += 1 let cnt += 1
endfor endfor
let snippet .= args
let snippet .= pair let snippet .= pair

View File

@ -67,5 +67,10 @@ function! s:suite.get_completed_snippet()
\ 'word' : 'foo{', 'abbr' : 'foo{piyo}', \ 'word' : 'foo{', 'abbr' : 'foo{piyo}',
\ 'menu' : '', 'info' : '' \ 'menu' : '', 'info' : ''
\ }), '${1:#:piyo}}${2}') \ }), '${1:#:piyo}}${2}')
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
\ 'word' : 'Dictionary(', 'abbr' : 'Dictionary<Key, Value>(foo)',
\ 'menu' : '', 'info' : ''
\ }), '<${1:#:Key}, ${2:#:Value}>${3:#:foo})${4}')
endfunction endfunction