diff --git a/README.md b/README.md index 35f1f08..1337876 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ -[![Stories in Ready](https://badge.waffle.io/SevereOverfl0w/async-clj-omni.png?label=ready&title=Ready)](https://waffle.io/SevereOverfl0w/async-clj-omni) # clj-async.nvim -Provides async clojure completion through [deoplete.nvim][] or [ncm][] and -[nrepl-python-client][]. +Provides async clojure completion for: + +* [deoplete.nvim][] +* [ncm2][] +* [asyncomplete.vim][] +* [coc.nvim][] +* [nvim-cmp][] Trying to use Fireplace's omnicompletion with auto-complete is painfully slow at times, making typing blocked. Using this module will be faster as @@ -23,29 +27,22 @@ your favourite plugin manager, mine is [vim-plug][] Plug 'clojure-vim/async-clj-omni' ``` -You also need to include the following lines in your init.vim: +You also need to include the following line in your init.vim: ```vim -let g:deoplete#keyword_patterns = {} -let g:deoplete#keyword_patterns.clojure = '[\w!$%&*+/:<=>?@\^_~\-\.#]*' +call deoplete#custom#option('keyword_patterns', {'clojure': '[\w!$%&*+/:<=>?@\^_~\-\.#]*'}) ``` -As I improve them, they may be PR'd into deoplete.vim, but I'm not yet -comfortable suggesting that change upstream. - -### Nvim Completion Manager +### Nvim Completion Manager 2 -1. Follow the install instructions for [ncm][]. +1. Follow the install instructions for [ncm2][]. 2. Add this plugin using your favourite plugin manager, ```vim Plug 'clojure-vim/async-clj-omni' ``` -That's it. It should "just" work, whether you're using Acid or Fireplace. - ### asyncomplete.vim - Registration: ``` @@ -56,6 +53,26 @@ au User asyncomplete_setup call asyncomplete#register_source({ \ }) ``` +### coc.nvim + +1. Follow the install instructions for [coc.nvim][]. +2. Add this plugin using your favourite plugin manager, + ```vim + Plug 'clojure-vim/async-clj-omni' + ``` + +### nvim-cmp + +1. Follow the install instructions for [nvim-cmp][]. +2. Add `{ name = 'async_clj_omni' }`, a complete example: + ```lua + cmp.setup({ + sources = { + { name = 'async_clj_omni' }, + } + }) + ``` + ## Developing ### Deoplete @@ -97,3 +114,7 @@ NVIM_PYTHON_LOG_FILE=logfile NVIM_PYTHON_LOG_LEVEL=DEBUG nvim [nrepl-python-client]: https://github.com/clojure-vim/nrepl-python-client [vim-plug]: https://github.com/junegunn/vim-plug [ncm]: https://github.com/roxma/nvim-completion-manager +[ncm2]: https://github.com/ncm2/ncm2 +[coc.nvim]: https://github.com/neoclide/coc.nvim +[asyncomplete.vim]: https://github.com/prabirshrestha/asyncomplete.vim +[nvim-cmp]: https://github.com/hrsh7th/nvim-cmp diff --git a/autoload/async_clj_omni/cmp.vim b/autoload/async_clj_omni/cmp.vim new file mode 100644 index 0000000..566dd0e --- /dev/null +++ b/autoload/async_clj_omni/cmp.vim @@ -0,0 +1,65 @@ +let s:source = {} + +function! s:source.new() abort + return deepcopy(s:source) +endfunction + +function! s:source.is_available() + if fireplace#op_available('complete') + return v:true + else + return v:false + endif +endfunction + +function! s:source.get_keyword_pattern(params) + " Minimum 2 letters because completion on "y" doesn't resolve any + " namespaces, but "ya" will resolve on "yada". + return '\k\k\+' +endfunction + +function! s:source.get_trigger_characters(params) + return ['/', '.', ':'] +endfunction + +" unfortunately f is for both function & static method. to workaround, we'll +" need to go to a lower level than fireplace#omnicomplete, which would lose us +" the context of the completion from surrounding lines. +let s:lsp_kinds = luaeval(" +\ (function() +\ local cmp = require'cmp' +\ return {f = cmp.lsp.CompletionItemKind.Function, +\ m = cmp.lsp.CompletionItemKind.Function, +\ v = cmp.lsp.CompletionItemKind.Variable, +\ s = cmp.lsp.CompletionItemKind.Keyword, +\ c = cmp.lsp.CompletionItemKind.Class, +\ k = cmp.lsp.CompletionItemKind.Keyword, +\ l = cmp.lsp.CompletionItemKind.Variable, +\ n = cmp.lsp.CompletionItemKind.Module, +\ i = cmp.lsp.CompletionItemKind.Field, +\ r = cmp.lsp.CompletionItemKind.File,} +\ end)()") + +function! s:coerce_to_lsp(vc) + return {'label': a:vc.word, + \ 'labelDetails': { + \ 'detail': a:vc.menu, + \ }, + \ 'documentation': a:vc.info, + \ 'kind': get(s:lsp_kinds, a:vc.kind, 1) + \ } +endf + +function! s:source.complete(params, callback) abort + let l:kw = a:params.context.cursor_before_line[(a:params.offset-1):] + + call fireplace#omnicomplete({candidates -> + \ a:callback(map(candidates, + \ {_, val -> s:coerce_to_lsp(val)})) + \ }, + \ l:kw) +endfunction + +function async_clj_omni#cmp#register() + call cmp#register_source('async_clj_omni', s:source.new()) +endf diff --git a/autoload/coc/source/async_clj_omni.vim b/autoload/coc/source/async_clj_omni.vim new file mode 100644 index 0000000..244e2b7 --- /dev/null +++ b/autoload/coc/source/async_clj_omni.vim @@ -0,0 +1,16 @@ +function! coc#source#async_clj_omni#init() abort + return { + \'shortcut': 'clj', + \'priority': 1, + \'filetypes': ['clojure'], + \'firstMatch': 0, + \'triggerCharacters': ['.', '/', ':'], + \} +endfunction + +function! coc#source#async_clj_omni#complete(opt, cb) abort + call fireplace#omnicomplete({candidates -> + \ a:cb(candidates) + \ }, + \ a:opt.input) +endfunction diff --git a/plugin/cmp_fireplace.vim b/plugin/cmp_fireplace.vim new file mode 100644 index 0000000..0874a62 --- /dev/null +++ b/plugin/cmp_fireplace.vim @@ -0,0 +1,4 @@ +augroup async_clj_omni_plugins + autocmd! + autocmd User CmpReady call async_clj_omni#cmp#register() +augroup END pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy