Fix #417 completed snippets parser
This commit is contained in:
parent
3071a45a4c
commit
e70864c53c
@ -26,12 +26,6 @@ call neosnippet#util#set_default(
|
|||||||
\ 'g:neosnippet#enable_optional_arguments', 1)
|
\ 'g:neosnippet#enable_optional_arguments', 1)
|
||||||
call neosnippet#util#set_default(
|
call neosnippet#util#set_default(
|
||||||
\ 'g:neosnippet#enable_auto_clear_markers', 1)
|
\ 'g:neosnippet#enable_auto_clear_markers', 1)
|
||||||
call neosnippet#util#set_default(
|
|
||||||
\ 'g:neosnippet#completed_pairs', {})
|
|
||||||
call neosnippet#util#set_default(
|
|
||||||
\ 'g:neosnippet#_completed_pairs',
|
|
||||||
\ {'_':{ '(' : ')', '{' : '}', '"' : '"', '[' : ']' }})
|
|
||||||
|
|
||||||
|
|
||||||
function! neosnippet#expandable_or_jumpable() abort
|
function! neosnippet#expandable_or_jumpable() abort
|
||||||
return neosnippet#mappings#expandable_or_jumpable()
|
return neosnippet#mappings#expandable_or_jumpable()
|
||||||
|
@ -297,27 +297,33 @@ function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, nex
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Set abbr
|
" Set abbr
|
||||||
let abbr = ''
|
let abbrs = []
|
||||||
if get(item, 'info', '') =~# '^.\+('
|
if get(item, 'info', '') =~# '^.\+('
|
||||||
let abbr = matchstr(item.info, '^\_s*\zs.*')
|
call add(abbrs, matchstr(item.info, '^\_s*\zs.*'))
|
||||||
elseif get(item, 'abbr', '') =~# '^.\+('
|
|
||||||
let abbr = item.abbr
|
|
||||||
elseif get(item, 'menu', '') =~# '^.\+('
|
|
||||||
let abbr = item.menu
|
|
||||||
elseif item.word =~# '^.\+(' || get(item, 'kind', '') == 'f'
|
|
||||||
let abbr = item.word
|
|
||||||
endif
|
endif
|
||||||
let abbr = escape(abbr, '\')
|
if get(item, 'abbr', '') =~# '^.\+('
|
||||||
|
call add(abbrs, item.abbr)
|
||||||
|
endif
|
||||||
|
if get(item, 'menu', '') =~# '^.\+('
|
||||||
|
call add(abbrs, item.menu)
|
||||||
|
endif
|
||||||
|
if item.word =~# '^.\+(' || get(item, 'kind', '') == 'f'
|
||||||
|
call add(abbrs, item.word)
|
||||||
|
endif
|
||||||
|
call map(abbrs, "escape(v:val, '\')")
|
||||||
|
|
||||||
let pairs = neosnippet#util#get_buffer_config(
|
" () Only supported
|
||||||
\ &filetype, '',
|
let pairs = {'(': ')'}
|
||||||
\ 'g:neosnippet#completed_pairs', 'g:neosnippet#_completed_pairs', {})
|
let no_key = index(keys(pairs), item.word[-1:]) < 0
|
||||||
let word_pattern = '\<' . neosnippet#util#escape_pattern(item.word)
|
let word_pattern = '\<' . neosnippet#util#escape_pattern(item.word)
|
||||||
let angle_pattern = word_pattern . '<.\+>(.*)'
|
let angle_pattern = word_pattern . '<.\+>(.*)'
|
||||||
let no_key = index(keys(pairs), item.word[-1:]) < 0
|
let check_pattern = word_pattern . '\%(<.\+>\)\?(.*)'
|
||||||
if no_key && abbr !~# word_pattern . '\%(<.\+>\)\?(.*)'
|
let abbrs = filter(abbrs, '!no_key || v:val =~# check_pattern')
|
||||||
|
|
||||||
|
if empty(abbrs)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
let abbr = abbrs[0]
|
||||||
|
|
||||||
let key = no_key ? '(' : item.word[-1:]
|
let key = no_key ? '(' : item.word[-1:]
|
||||||
if a:next_text[:0] ==# key
|
if a:next_text[:0] ==# key
|
||||||
|
@ -87,11 +87,6 @@ function! s:suite.get_completed_snippet() abort
|
|||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, 'foo(', ''), '${1:#:hoge}${2:#:, ...})${3}')
|
\ }, 'foo(', ''), '${1:#:hoge}${2:#:, ...})${3}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
|
||||||
\ 'word' : 'foo{', 'abbr' : 'foo{',
|
|
||||||
\ 'menu' : '', 'info' : ''
|
|
||||||
\ }, 'foo{', ''), '${1}}${2}')
|
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'Dictionary', 'abbr' : 'Dictionary<Key, Value>(foo)',
|
\ 'word' : 'Dictionary', 'abbr' : 'Dictionary<Key, Value>(foo)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
@ -128,14 +123,14 @@ function! s:suite.get_completed_snippet() abort
|
|||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, 'forEach', ''), '(${1:#:BiConsumer<>})${2}')
|
\ }, 'forEach', ''), '(${1:#:BiConsumer<>})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
|
||||||
\ 'word' : 'for[', 'abbr' : '',
|
|
||||||
\ 'menu' : '', 'info' : ''
|
|
||||||
\ }, 'for[', ''), '${1}]${2}')
|
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'something', 'abbr' : 'something(else)',
|
\ 'word' : 'something', 'abbr' : 'something(else)',
|
||||||
\ 'menu' : '', 'info' : '', 'snippet' : '(${1:custom})${2}'
|
\ 'menu' : '', 'info' : '', 'snippet' : '(${1:custom})${2}'
|
||||||
\ }, 'something', ''), '(${1:custom})${2}')
|
\ }, 'something', ''), '(${1:custom})${2}')
|
||||||
|
|
||||||
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
|
\ 'word' : 'something', 'abbr' : 'something(else)',
|
||||||
|
\ 'menu' : '', 'info' : 'func()', 'snippet' : '(${1:custom})${2}'
|
||||||
|
\ }, 'something', ''), '(${1:custom})${2}')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user