Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Split out providers.vim #242

Merged
merged 3 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ CHANGELOG

## [unreleased]

### Added

- New provider `:Clap providers` for listing all the providers by splitting out the previous anonymous `_` provider.([#242](https://github.com/liuchengxu/vim-clap/pull/242))

### Improved

- Refine `:Clap debug` and require it in the bug report. ([#241](https://github.com/liuchengxu/vim-clap/pull/241))
Expand Down
34 changes: 2 additions & 32 deletions autoload/clap.vim
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ function! s:inject_default_impl_is_ok(provider_info) abort
return v:true
endfunction

function! s:_sink(selected) abort
let provider = matchstr(a:selected, '^\(.*\)\ze:')
" a sink for "Clap _" (dispatch to other builtin clap providers).
call timer_start(0, {-> clap#_for(provider)})
endfunction

function! clap#_init() abort
if has_key(g:clap.provider._(), 'source')
let Source = g:clap.provider._().source
Expand Down Expand Up @@ -134,7 +128,7 @@ function! clap#_init() abort
call g:clap.provider.init_display_win()

" Ensure the filetype is empty on init.
" Each provider can set its own filetype for the highlight purpose.
" Each provider can set its own syntax for the highlight purpose.
call g:clap.display.setbufvar('&filetype', '')
endfunction

Expand Down Expand Up @@ -308,32 +302,8 @@ function! clap#for(provider_id_or_alias) abort
call g:clap.open_win()
endfunction

function! s:_source() abort
if !exists('s:global_source')
let s:global_source = []
for provider_id in s:builtin_providers
let provider_path = globpath(&runtimepath, 'autoload/clap/provider/'.provider_id.'.vim')
if file_readable(provider_path)
let desc_line = readfile(provider_path, '', 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
endif
endfor
endif
return s:global_source
endfunction

if !exists('g:clap')
call clap#init#()
call clap#register('_', {
\ 'source': function('s:_source'),
\ 'sink': function('s:_sink'),
\ 'on_enter': { -> g:clap.display.setbufvar('&syntax', 'clap_global') },
\ })
endif

function! s:parse_opts(args) abort
Expand Down Expand Up @@ -382,7 +352,7 @@ function! clap#(bang, ...) abort
endif

if a:0 == 0
let provider_id_or_alias = '_'
let provider_id_or_alias = 'providers'
let g:clap.provider.args = []
else
if a:000 == ['debug']
Expand Down
38 changes: 38 additions & 0 deletions autoload/clap/provider/providers.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
" 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 = matchstr(a:selected, '^\(.*\)\ze:')
" 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 provider_id in g:clap#builtin_providers
let provider_path = globpath(&runtimepath, 'autoload/clap/provider/'.provider_id.'.vim')
if file_readable(provider_path)
let desc_line = readfile(provider_path, '', 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
endif
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
File renamed without changes.