forked from liuchengxu/vim-clap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproviders.vim
More file actions
57 lines (49 loc) · 1.89 KB
/
providers.vim
File metadata and controls
57 lines (49 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
" Author: liuchengxu <xuliuchengxlc@gmail.com>
" Description: List all the providers.
let s:save_cpo = &cpoptions
set cpoptions&vim
let s:providers = {}
function! s:providers.sink(selected) abort
let provider = a:selected[: stridx(a:selected, ':') - 1]
" a sink for "Clap providers" (dispatch to other builtin clap providers).
call timer_start(0, {-> clap#_for(provider)})
endfunction
function! s:providers.source() abort
if !exists('s:global_source')
let s:global_source = []
for autoload_provider in split(globpath(&runtimepath, 'autoload/clap/provider/*.vim'), "\n")
let provider_id = fnamemodify(autoload_provider, ':t:r')
if file_readable(autoload_provider)
let desc_line = readfile(autoload_provider, '', 2)[-1]
let desc = matchstr(desc_line, '^.*Description: \zs\(.*\)\ze\.\?$')
if empty(desc)
call add(s:global_source, provider_id.':')
else
call add(s:global_source, provider_id.': '.desc)
endif
else
call add(s:global_source, provider_id.':')
endif
endfor
" `description` is required, otherwise we can't distinguish whether the variable name
" like `g:clap_provider_yanks_history` is a name of some provider or merely a control
" variable of a provider.
let maybe_user_var_providers = filter(keys(g:), 'v:val =~# "^clap_provider_"')
for maybe_var_provider in maybe_user_var_providers
try
let evaled = eval('g:'.maybe_var_provider)
if type(evaled) == v:t_dict
let provider_id = matchstr(maybe_var_provider, 'clap_provider_\zs\(.*\)')
call add(s:global_source, provider_id.': '.evaled['description'])
endif
catch
" Ignore
endtry
endfor
endif
return s:global_source
endfunction
let s:providers.syntax = 'clap_providers'
let g:clap#provider#providers# = s:providers
let &cpoptions = s:save_cpo
unlet s:save_cpo