diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 7e4c3a7..8ea779d 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -26,12 +26,6 @@ call neosnippet#util#set_default( \ 'g:neosnippet#enable_optional_arguments', 1) call neosnippet#util#set_default( \ '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 return neosnippet#mappings#expandable_or_jumpable() diff --git a/autoload/neosnippet/parser.vim b/autoload/neosnippet/parser.vim index 5a14313..1b1b1ae 100644 --- a/autoload/neosnippet/parser.vim +++ b/autoload/neosnippet/parser.vim @@ -297,27 +297,33 @@ function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, nex endif " Set abbr - let abbr = '' + let abbrs = [] if get(item, 'info', '') =~# '^.\+(' - let abbr = 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 + call add(abbrs, matchstr(item.info, '^\_s*\zs.*')) 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( - \ &filetype, '', - \ 'g:neosnippet#completed_pairs', 'g:neosnippet#_completed_pairs', {}) + " () Only supported + let pairs = {'(': ')'} + let no_key = index(keys(pairs), item.word[-1:]) < 0 let word_pattern = '\<' . neosnippet#util#escape_pattern(item.word) let angle_pattern = word_pattern . '<.\+>(.*)' - let no_key = index(keys(pairs), item.word[-1:]) < 0 - if no_key && abbr !~# word_pattern . '\%(<.\+>\)\?(.*)' + let check_pattern = word_pattern . '\%(<.\+>\)\?(.*)' + let abbrs = filter(abbrs, '!no_key || v:val =~# check_pattern') + + if empty(abbrs) return '' endif + let abbr = abbrs[0] let key = no_key ? '(' : item.word[-1:] if a:next_text[:0] ==# key diff --git a/test/functions.vim b/test/functions.vim index 7ecce41..7a40d5a 100644 --- a/test/functions.vim +++ b/test/functions.vim @@ -87,11 +87,6 @@ function! s:suite.get_completed_snippet() abort \ 'menu' : '', 'info' : '' \ }, '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({ \ 'word' : 'Dictionary', 'abbr' : 'Dictionary(foo)', \ 'menu' : '', 'info' : '' @@ -128,14 +123,14 @@ function! s:suite.get_completed_snippet() abort \ 'menu' : '', 'info' : '' \ }, '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({ \ 'word' : 'something', 'abbr' : 'something(else)', \ 'menu' : '', 'info' : '', 'snippet' : '(${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