From b65efdced5ab98ed9fedca5fab99fc51592bd56e Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 9 Oct 2020 18:14:07 +0900 Subject: [PATCH] Support custom filter (#185) --- autoload/asyncomplete.vim | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/autoload/asyncomplete.vim b/autoload/asyncomplete.vim index cef9f58..fc3a4cd 100644 --- a/autoload/asyncomplete.vim +++ b/autoload/asyncomplete.vim @@ -475,20 +475,25 @@ function! s:default_preprocessor(options, matches) abort for [l:source_name, l:matches] in items(a:matches) let l:startcol = l:matches['startcol'] let l:base = a:options['typed'][l:startcol - 1:] - for l:item in l:matches['items'] - if stridx(l:item['word'], l:base) == 0 - " Strip pair characters. If pre-typed text is '"', candidates - " should have '"' suffix. - if has_key(s:pair, l:base[0]) - let [l:lhs, l:rhs, l:str] = [l:base[0], s:pair[l:base[0]], l:item['word']] - if len(l:str) > 1 && l:str[0] ==# l:lhs && l:str[-1:] ==# l:rhs - let l:item['word'] = l:str[:-2] + if has_key(s:sources[l:source_name], 'filter') + let [l:items, l:startcols] = s:sources[l:source_name].filter(l:matches, l:startcol, l:base) + else + for l:item in l:matches['items'] + if stridx(l:item['word'], l:base) == 0 + " Strip pair characters. If pre-typed text is '"', candidates + " should have '"' suffix. + if has_key(s:pair, l:base[0]) + let [l:lhs, l:rhs, l:str] = [l:base[0], s:pair[l:base[0]], l:item['word']] + if len(l:str) > 1 && l:str[0] ==# l:lhs && l:str[-1:] ==# l:rhs + let l:before = l:item['word'] + let l:item['word'] = l:str[:-2] + endif endif + let l:startcols += [l:startcol] + call add(l:items, l:item) endif - let l:startcols += [l:startcol] - call add(l:items, l:item) - endif - endfor + endfor + endif endfor let a:options['startcol'] = min(l:startcols)