Browse Source

Fix #417 completed snippets parser

PR/fix-warning
Shougo Matsushita 6 years ago
parent
commit
e70864c53c
3 changed files with 24 additions and 29 deletions
  1. +0
    -6
      autoload/neosnippet.vim
  2. +20
    -14
      autoload/neosnippet/parser.vim
  3. +4
    -9
      test/functions.vim

+ 0
- 6
autoload/neosnippet.vim View File

@@ -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()


+ 20
- 14
autoload/neosnippet/parser.vim View File

@@ -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


+ 4
- 9
test/functions.vim View File

@@ -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<Key, Value>(foo)',
\ 'menu' : '', 'info' : ''
@@ -129,13 +124,13 @@ function! s:suite.get_completed_snippet() abort
\ }, 'forEach', ''), '(${1:#:BiConsumer<>})${2}')

call s:assert.equals(neosnippet#parser#_get_completed_snippet({
\ 'word' : 'for[', 'abbr' : '',
\ 'menu' : '', 'info' : ''
\ }, 'for[', ''), '${1}]${2}')
\ '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' : '', 'snippet' : '(${1:custom})${2}'
\ 'menu' : '', 'info' : 'func()', 'snippet' : '(${1:custom})${2}'
\ }, 'something', ''), '(${1:custom})${2}')
endfunction


Loading…
Cancel
Save