Add support for Cider-nrepl 0.9.0 complete op

Response from complete operation now returns list of maps containing
e.g. namespace and type of the completion candidate.
This change adds a new type check to check if complete returned list of
maps and converts those maps to format required by omnicomplete.
In addition to candidate name its type is now shown. The type is
shortned to one character.
This commit is contained in:
Juho Teperi 2015-05-15 22:23:00 +03:00
parent 49153a39fc
commit 44e766d5a5
1 changed files with 19 additions and 1 deletions

View File

@ -81,6 +81,22 @@ function! fireplace#ns_complete(A, L, P) abort
return filter(map(matches, 's:to_ns(v:val)'), 'a:A ==# "" || a:A ==# v:val[0 : strlen(a:A)-1]') return filter(map(matches, 's:to_ns(v:val)'), 'a:A ==# "" || a:A ==# v:val[0 : strlen(a:A)-1]')
endfunction endfunction
let s:short_types = {
\ 'function': 'f',
\ 'macro': 'm',
\ 'var': 'v',
\ 'special-form': 's',
\ 'class': 'c'
\ }
function! s:candidate(val) abort
let type = get(a:val, 'type', '')
return {
\ 'word': get(a:val, 'candidate'),
\ 'kind': get(s:short_types, type, type)
\ }
endfunction
function! fireplace#omnicomplete(findstart, base) abort function! fireplace#omnicomplete(findstart, base) abort
if a:findstart if a:findstart
let line = getline('.')[0 : col('.')-2] let line = getline('.')[0 : col('.')-2]
@ -93,7 +109,9 @@ function! fireplace#omnicomplete(findstart, base) abort
let trans = '{"word": (v:val =~# ''[./]'' ? "" : matchstr(a:base, ''^.\+/'')) . v:val}' let trans = '{"word": (v:val =~# ''[./]'' ? "" : matchstr(a:base, ''^.\+/'')) . v:val}'
let value = get(response[0], 'value', get(response[0], 'completions')) let value = get(response[0], 'value', get(response[0], 'completions'))
if type(value) == type([]) if type(value) == type([])
if type(get(value, 0)) == type([]) if type(get(value, 0)) == type({})
return map(value, 's:candidate(v:val)')
elseif type(get(value, 0)) == type([])
return map(value[0], trans) return map(value[0], trans)
elseif type(get(value, 0)) == type('') elseif type(get(value, 0)) == type('')
return map(value, trans) return map(value, trans)