From 44e766d5a5e68ee1b429720f3b057d592bb1a617 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Fri, 15 May 2015 22:23:00 +0300 Subject: [PATCH] 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. --- plugin/fireplace.vim | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugin/fireplace.vim b/plugin/fireplace.vim index e74d47e..c207e1a 100644 --- a/plugin/fireplace.vim +++ b/plugin/fireplace.vim @@ -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]') 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 if a:findstart 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 value = get(response[0], 'value', get(response[0], 'completions')) 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) elseif type(get(value, 0)) == type('') return map(value, trans)