├── Readme.md └── autoload └── coc └── source └── neoinclude.vim /Readme.md: -------------------------------------------------------------------------------- 1 | # coc-neoinclude 2 | 3 | Include completon source for [coc.nvim](https://github.com/neoclide/coc.nvim) using 4 | [neoinclude.vim](https://github.com/Shougo/neoinclude.vim) 5 | 6 | **Note:** this source invode vim function that could be quite slow, so make sure 7 | your `coc.preferences.timeout` is not too low, otherwise it may timeout. 8 | 9 | ## Install 10 | 11 | For vim-plug user, add: 12 | 13 | ``` 14 | Plug 'Shougo/neoinclude.vim' 15 | Plug 'jsfaint/coc-neoinclude' 16 | Plug 'neoclide/coc.nvim', {'tag': '*', 'do': { -> coc#util#install()}} 17 | ``` 18 | 19 | to your `.vimrc` and run `:PlugInstall` 20 | 21 | ## LICENSE 22 | 23 | MIT 24 | -------------------------------------------------------------------------------- /autoload/coc/source/neoinclude.vim: -------------------------------------------------------------------------------- 1 | function! coc#source#neoinclude#init() abort 2 | return { 3 | \ 'priority': 9, 4 | \ 'shortcut': 'FI', 5 | \} 6 | endfunction 7 | 8 | function! coc#source#neoinclude#should_complete(opt) abort 9 | return 1 10 | endfunction 11 | 12 | function! coc#source#neoinclude#get_startcol(opt) abort 13 | let colnr = a:opt['colnr'] 14 | let part = colnr == 1 ? '' : a:opt['line'][0:colnr-2] 15 | 16 | let col = neoinclude#file_include#get_complete_position(part) 17 | let ch = a:opt['line'][col + 1] 18 | if ch ==# ':' 19 | return col + 2 20 | endif 21 | return col 22 | endfunction 23 | 24 | function! coc#source#neoinclude#complete(opt, cb) abort 25 | let colnr = a:opt['colnr'] 26 | let input = a:opt['input'] 27 | let part = a:opt['line'][0:colnr - 2] 28 | 29 | let changed = get(a:opt, 'changed', 0) 30 | if changed < 0 31 | let changed = 0 32 | endif 33 | let items = neoinclude#file_include#get_include_files(part) 34 | call a:cb(s:Filter(input, items, changed)) 35 | endfunction 36 | 37 | function! s:Filter(input, items, index) 38 | let ch = a:input[a:index] 39 | let colon = a:input =~# '\v^(g|l|s):' 40 | let res = [] 41 | for item in a:items 42 | let word = item['word'] 43 | if !empty(ch) && word[a:index] !=# ch 44 | continue 45 | endif 46 | if !colon && word[1:1] =~# ':' 47 | continue 48 | endif 49 | let o = {} 50 | for [key, value] in items(item) 51 | if key ==# 'word' && value =~# '($' 52 | let o[key] = value[0:-2] 53 | elseif key ==# 'word' && value =~# '()$' 54 | let o[key] = value[0:-3] 55 | elseif key ==# 'word' && colon 56 | let o[key] = value[2:] 57 | else 58 | let o[key] = value 59 | endif 60 | endfor 61 | call add(res, o) 62 | endfor 63 | return res 64 | endfunction 65 | --------------------------------------------------------------------------------