Skip to content

Commit

Permalink
Improve denops check
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Feb 19, 2022
1 parent 86196d6 commit ca165d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
40 changes: 25 additions & 15 deletions autoload/ddu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,41 @@ function! ddu#get_item_actions(name, items) abort
return ddu#_request('getItemActions', [a:name, a:items])
endfunction

function! ddu#_request(name, args) abort
if s:init(a:name)
function! ddu#_request(method, args) abort
if s:init()
return {}
endif

" Note: If call denops#plugin#wait() in vim_starting, freezed!
if denops#server#status() !=# 'running' && has('vim_starting')
call ddu#util#print_error(
\ printf('You cannot call "%s" before denops.vim initialized.',
\ a:method))
return {}
endif

call denops#plugin#wait('ddu')
return denops#request('ddu', a:name, a:args)
return denops#request('ddu', a:method, a:args)
endfunction
function! ddu#_notify(name, args) abort
if s:init(a:name)
function! ddu#_notify(method, args) abort
if s:init()
return {}
endif

call denops#plugin#wait('ddu')
return denops#notify('ddu', a:name, a:args)
if ddu#_denops_running()
call denops#plugin#wait('ddu')
call denops#notify('ddu', a:method, a:args)
else
" Lazy call notify
execute printf('autocmd User DDUReady call ' .
\ 'denops#notify("ddu", "%s", %s)',
\ a:method, string(a:args))
endif

return {}
endfunction

function! s:init(name) abort
function! s:init() abort
if exists('g:ddu#_initialized')
return
endif
Expand All @@ -60,13 +77,6 @@ function! s:init(name) abort
else
autocmd ddu User DenopsReady silent! call ddu#_register()
endif

" Note: If call denops#plugin#wait() in vim_starting, freezed!
if denops#server#status() !=# 'running' && has('vim_starting')
call ddu#util#print_error(
\ printf('You cannot call "%s" before denops initialized.', a:name))
return 1
endif
endfunction

let s:root_dir = fnamemodify(expand('<sfile>'), ':h:h')
Expand Down
22 changes: 6 additions & 16 deletions autoload/ddu/custom.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ function! ddu#custom#patch_global(key_or_dict, ...) abort
call ddu#util#print_error('The args is too much: ' . string(a:000))
endif
let dict = s:normalize_key_or_dict(a:key_or_dict, get(a:000, 0, ''))
call s:notify('patchGlobal', [dict])
call ddu#_notify('patchGlobal', [dict])
endfunction
function! ddu#custom#patch_local(name, key_or_dict, ...) abort
if a:0 > 1
call ddu#util#print_error('The args is too much: ' . string(a:000))
endif
let dict = s:normalize_key_or_dict(a:key_or_dict, get(a:000, 0, ''))
call s:notify('patchLocal', [dict, a:name])
call ddu#_notify('patchLocal', [dict, a:name])
endfunction

function! ddu#custom#set_global(dict) abort
call s:notify('setGlobal', [a:dict])
call ddu#_notify('setGlobal', [a:dict])
endfunction
function! ddu#custom#set_local(name, dict) abort
call s:notify('setLocal', [a:dict, a:name])
call ddu#_notify('setLocal', [a:dict, a:name])
endfunction

let s:aliases = { 'ui': {}, 'source': {}, 'filter': {}, 'kind': {} }
Expand All @@ -28,7 +28,7 @@ function! ddu#custom#alias(type, alias, base) abort
endif

let s:aliases[a:type][a:alias] = a:base
call s:notify('alias', [a:type, a:alias, a:base])
call ddu#_notify('alias', [a:type, a:alias, a:base])
endfunction

let s:custom_actions = {}
Expand All @@ -41,7 +41,7 @@ function! ddu#custom#action(type, source_kind_name, action_name, func) abort
let s:custom_actions[string(a:func)] = a:func
endfor

call s:notify('patchGlobal', [
call ddu#_notify('patchGlobal', [
\ a:type ==# 'source' ?
\ { 'sourceOptions': dict } : { 'kindOptions': dict }
\ ])
Expand All @@ -64,16 +64,6 @@ function! ddu#custom#get_aliases() abort
return s:aliases
endfunction

function! s:notify(method, args) abort
if ddu#_denops_running()
call denops#notify('ddu', a:method, a:args)
else
execute printf('autocmd User DDUReady call ' .
\ 'denops#notify("ddu", "%s", %s)',
\ a:method, string(a:args))
endif
endfunction

function! s:normalize_key_or_dict(key_or_dict, value) abort
if type(a:key_or_dict) == v:t_dict
return a:key_or_dict
Expand Down

0 comments on commit ca165d2

Please sign in to comment.