Last active
June 11, 2018 21:55
-
-
Save bstaletic/71b6fa1c549640aeba1848dfd4b7f59a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Completing functions using UltiSnips | |
function! ycm#onCompleteDone() abort | |
let l:info = v:completed_item.info | |
let l:startIdx = stridx(l:info,'(') | |
let l:endIdx = strridx(l:info,')') | |
"echo 'abbr = ' . string(v:completed_item) | |
if l:endIdx - l:startIdx > 1 | |
let l:argsStr = strpart(l:info, l:startIdx+1, l:endIdx - l:startIdx -1) | |
"let argsList = split(argsStr, ",") | |
let l:argsList = [] | |
let l:arg = '' | |
let l:countParen = 0 | |
for l:i in range(strlen(l:argsStr)) | |
if l:argsStr[l:i] ==# ',' && l:countParen == 0 | |
call add(l:argsList, l:arg) | |
let l:arg = '' | |
elseif l:argsStr[l:i] ==# '(' | |
let l:countParen += 1 | |
let l:arg .= l:argsStr[l:i] | |
elseif l:argsStr[l:i] ==# ')' | |
let l:countParen -= 1 | |
let l:arg .= l:argsStr[l:i] | |
else | |
let l:arg .= l:argsStr[l:i] | |
endif | |
endfor | |
if l:arg !=# '' && l:countParen ==# 0 | |
call add(l:argsList, l:arg[:stridx(l:arg,')')-1]) | |
redir => g:foo | |
echo l:arg | |
redir END | |
endif | |
else | |
let l:argsList = [] | |
endif | |
if len(l:argsList) == 0 | |
return UltiSnips#Anon('') | |
endif | |
let l:snippet = '(' | |
if len(l:argsList) > 0 && | |
\ exists('g:ycm_spaces_in_parens') && | |
\ g:ycm_spaces_in_parens == 1 | |
let l:snippet .= ' ' | |
endif | |
let l:c = 1 | |
for l:i in l:argsList | |
if l:c > 1 | |
let l:snippet .= ', ' | |
endif | |
" strip space | |
let l:arg = substitute(l:i, '^\s*\(.\{-}\)\s*$', '\1', '') | |
let l:snippet .= '${' . l:c . ':' . l:arg . '}' | |
let l:c += 1 | |
endfor | |
if len(l:argsList) > 0 && | |
\ exists('g:ycm_spaces_in_parens') && | |
\ g:ycm_spaces_in_parens == 1 | |
let l:snippet .= ' ' | |
endif | |
let l:snippet .= ')' . '$0' | |
return UltiSnips#Anon(l:snippet) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment