|
| 1 | +let s:source = {} |
| 2 | + |
| 3 | +function! s:source.new() abort |
| 4 | + return deepcopy(s:source) |
| 5 | +endfunction |
| 6 | + |
| 7 | +function! s:source.is_available() |
| 8 | + if fireplace#op_available('complete') |
| 9 | + return v:true |
| 10 | + else |
| 11 | + return v:false |
| 12 | + endif |
| 13 | +endfunction |
| 14 | + |
| 15 | +function! s:source.get_keyword_pattern(params) |
| 16 | + " Minimum 2 letters because completion on "y" doesn't resolve any |
| 17 | + " namespaces, but "ya" will resolve on "yada". |
| 18 | + return '\k\k\+' |
| 19 | +endfunction |
| 20 | + |
| 21 | +function! s:source.get_trigger_characters(params) |
| 22 | + return ['/', '.', ':'] |
| 23 | +endfunction |
| 24 | + |
| 25 | +" unfortunately f is for both function & static method. to workaround, we'll |
| 26 | +" need to go to a lower level than fireplace#omnicomplete, which would lose us |
| 27 | +" the context of the completion from surrounding lines. |
| 28 | +let s:lsp_kinds = luaeval(" |
| 29 | +\ (function() |
| 30 | +\ local cmp = require'cmp' |
| 31 | +\ return {f = cmp.lsp.CompletionItemKind.Function, |
| 32 | +\ m = cmp.lsp.CompletionItemKind.Function, |
| 33 | +\ v = cmp.lsp.CompletionItemKind.Variable, |
| 34 | +\ s = cmp.lsp.CompletionItemKind.Keyword, |
| 35 | +\ c = cmp.lsp.CompletionItemKind.Class, |
| 36 | +\ k = cmp.lsp.CompletionItemKind.Keyword, |
| 37 | +\ l = cmp.lsp.CompletionItemKind.Variable, |
| 38 | +\ n = cmp.lsp.CompletionItemKind.Module, |
| 39 | +\ i = cmp.lsp.CompletionItemKind.Field, |
| 40 | +\ r = cmp.lsp.CompletionItemKind.File,} |
| 41 | +\ end)()") |
| 42 | + |
| 43 | +function! s:coerce_to_lsp(vc) |
| 44 | + return {'label': a:vc.word, |
| 45 | + \ 'labelDetails': { |
| 46 | + \ 'detail': a:vc.menu, |
| 47 | + \ }, |
| 48 | + \ 'documentation': a:vc.info, |
| 49 | + \ 'kind': get(s:lsp_kinds, a:vc.kind, 1) |
| 50 | + \ } |
| 51 | +endf |
| 52 | + |
| 53 | +function! s:source.complete(params, callback) abort |
| 54 | + let l:kw = a:params.context.cursor_before_line[(a:params.offset-1):] |
| 55 | + |
| 56 | + call fireplace#omnicomplete({candidates -> |
| 57 | + \ a:callback(map(candidates, |
| 58 | + \ {_, val -> s:coerce_to_lsp(val)})) |
| 59 | + \ }, |
| 60 | + \ l:kw) |
| 61 | +endfunction |
| 62 | + |
| 63 | +function async_clj_omni#cmp#register() |
| 64 | + call cmp#register_source('async_clj_omni', s:source.new()) |
| 65 | +endf |
0 commit comments