Fix #359 completed snippets problem
This commit is contained in:
parent
22bf961126
commit
4cdeabfa89
@ -47,7 +47,8 @@ function! neosnippet#mappings#completed_expandable() abort "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let snippet = neosnippet#parser#_get_completed_snippet(
|
let snippet = neosnippet#parser#_get_completed_snippet(
|
||||||
\ v:completed_item, neosnippet#util#get_next_text())
|
\ v:completed_item, neosnippet#util#get_cur_text(),
|
||||||
|
\ neosnippet#util#get_next_text())
|
||||||
return snippet != ''
|
return snippet != ''
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! s:enabled_completed_snippet() abort "{{{
|
function! s:enabled_completed_snippet() abort "{{{
|
||||||
@ -170,7 +171,7 @@ endfunction"}}}
|
|||||||
function! s:snippets_expand(cur_text, col) abort "{{{
|
function! s:snippets_expand(cur_text, col) abort "{{{
|
||||||
if s:enabled_completed_snippet()
|
if s:enabled_completed_snippet()
|
||||||
let snippet = neosnippet#parser#_get_completed_snippet(
|
let snippet = neosnippet#parser#_get_completed_snippet(
|
||||||
\ v:completed_item, neosnippet#util#get_next_text())
|
\ v:completed_item, a:cur_text, neosnippet#util#get_next_text())
|
||||||
if snippet != ''
|
if snippet != ''
|
||||||
call neosnippet#view#_insert(snippet, {}, a:cur_text, a:col)
|
call neosnippet#view#_insert(snippet, {}, a:cur_text, a:col)
|
||||||
return 0
|
return 0
|
||||||
|
@ -298,10 +298,14 @@ function! neosnippet#parser#_initialize_snippet_options() abort "{{{
|
|||||||
\ }
|
\ }
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! neosnippet#parser#_get_completed_snippet(completed_item, next_text) abort "{{{
|
function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, next_text) abort "{{{
|
||||||
let item = a:completed_item
|
let item = a:completed_item
|
||||||
|
|
||||||
if has_key(item, "snippet")
|
if strridx(a:cur_text, item.word) != len(a:cur_text) - len(item.word)
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_key(item, 'snippet')
|
||||||
return item.snippet
|
return item.snippet
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -36,102 +36,107 @@ function! s:suite.get_completed_snippet() abort
|
|||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo()',
|
\ 'word' : 'foo(', 'abbr' : 'foo()',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), ')${1}')
|
\ }, 'foo(', ''), ')${1}')
|
||||||
|
|
||||||
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
|
\ 'word' : 'foo(', 'abbr' : 'foo()',
|
||||||
|
\ 'menu' : '', 'info' : ''
|
||||||
|
\ }, 'foo)', ''), '')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : '',
|
\ 'word' : 'foo(', 'abbr' : '',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1})${2}')
|
\ }, 'foo(', ''), '${1})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge)',
|
\ 'word' : 'foo(', 'abbr' : 'foo(hoge)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:hoge})${2}')
|
\ }, 'foo(', ''), '${1:#:hoge})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo', 'abbr' : 'foo(hoge)',
|
\ 'word' : 'foo', 'abbr' : 'foo(hoge)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '(${1:#:hoge})${2}')
|
\ }, 'foo', ''), '(${1:#:hoge})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, piyo)',
|
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, piyo)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:hoge}, ${2:#:piyo})${3}')
|
\ }, 'foo(', ''), '${1:#:hoge}, ${2:#:piyo})${3}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, piyo(foobar))',
|
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, piyo(foobar))',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:hoge}, ${2:#:piyo()})${3}')
|
\ }, 'foo(', ''), '${1:#:hoge}, ${2:#:piyo()})${3}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge[, abc])',
|
\ 'word' : 'foo(', 'abbr' : 'foo(hoge[, abc])',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:hoge[, abc]})${2}')
|
\ }, 'foo(', ''), '${1:#:hoge[, abc]})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo(...)',
|
\ 'word' : 'foo(', 'abbr' : 'foo(...)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:...})${2}')
|
\ }, 'foo(', ''), '${1:#:...})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, ...)',
|
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, ...)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:hoge}${2:#:, ...})${3}')
|
\ }, 'foo(', ''), '${1:#:hoge}${2:#:, ...})${3}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo{', 'abbr' : 'foo{',
|
\ 'word' : 'foo{', 'abbr' : 'foo{',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1}}${2}')
|
\ }, 'foo{', ''), '${1}}${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'foo{', 'abbr' : 'foo{piyo}',
|
\ 'word' : 'foo{', 'abbr' : 'foo{piyo}',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:piyo}}${2}')
|
\ }, 'foo{', ''), '${1:#:piyo}}${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' : ''
|
||||||
\ }, ''), '<${1:#:Key}, ${2:#:Value}>(${3:#:foo})${4}')
|
\ }, 'Dictionary', ''), '<${1:#:Key}, ${2:#:Value}>(${3:#:foo})${4}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'Dictionary(',
|
\ 'word' : 'Dictionary(',
|
||||||
\ 'abbr' : 'Dictionary<Key, Value> Dictionary(foo)',
|
\ 'abbr' : 'Dictionary<Key, Value> Dictionary(foo)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1:#:foo})${2}')
|
\ }, 'Dictionary(', ''), '${1:#:foo})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'Dictionary(', 'abbr' : '',
|
\ 'word' : 'Dictionary(', 'abbr' : '',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, '('), '')
|
\ }, 'Dictionary(', '('), '')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'Dictionary(', 'abbr' : 'Dictionary(foo)',
|
\ 'word' : 'Dictionary(', 'abbr' : 'Dictionary(foo)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, '('), '')
|
\ }, 'Dictionary(', '('), '')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'Dictionary(', 'abbr' : 'Dictionary(foo)',
|
\ 'word' : 'Dictionary(', 'abbr' : 'Dictionary(foo)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ')'), '${1:#:foo})${2}')
|
\ }, 'Dictionary(', ')'), '${1:#:foo})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'Dictionary', 'abbr' : 'Dictionary(foo)',
|
\ 'word' : 'Dictionary', 'abbr' : 'Dictionary(foo)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '(${1:#:foo})${2}')
|
\ }, 'Dictionary', ''), '(${1:#:foo})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'forEach', 'abbr' : 'forEach(BiConsumer<Object, Object>)',
|
\ 'word' : 'forEach', 'abbr' : 'forEach(BiConsumer<Object, Object>)',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '(${1:#:BiConsumer<>})${2}')
|
\ }, 'forEach', ''), '(${1:#:BiConsumer<>})${2}')
|
||||||
|
|
||||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||||
\ 'word' : 'for[', 'abbr' : '',
|
\ 'word' : 'for[', 'abbr' : '',
|
||||||
\ 'menu' : '', 'info' : ''
|
\ 'menu' : '', 'info' : ''
|
||||||
\ }, ''), '${1}]${2}')
|
\ }, '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}'
|
||||||
\ }, ''), '(${1:custom})${2}')
|
\ }, 'something', ''), '(${1:custom})${2}')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user