mirror of
https://github.com/neovim/neovim.git
synced 2025-01-01 17:23:36 -07:00
74 lines
1.7 KiB
VimL
74 lines
1.7 KiB
VimL
if exists('s:loaded_perl_provider')
|
|
finish
|
|
endif
|
|
|
|
let s:loaded_perl_provider = 1
|
|
|
|
function! provider#perl#Detect() abort
|
|
" use g:perl_host_prof if set or check if perl is on the path
|
|
let prog = get(g:, 'perl_host_prog', executable('perl') ? 'perl' : '')
|
|
|
|
" if perl is available, make sure the required module is available
|
|
if prog != ''
|
|
let job_id = jobstart(prog.' -MNeovim::Ext -e "exit 0"', {'stdout_buffered': v:true})
|
|
let result = jobwait([job_id])
|
|
if result[0] != 0
|
|
let prog = ''
|
|
endif
|
|
endif
|
|
|
|
return prog
|
|
endfunction
|
|
|
|
function! provider#perl#Prog() abort
|
|
return s:prog
|
|
endfunction
|
|
|
|
function! provider#perl#Require(host) abort
|
|
if s:err != ''
|
|
echoerr s:err
|
|
return
|
|
endif
|
|
|
|
let prog = provider#perl#Prog()
|
|
let args = [s:prog, '-e', 'use Neovim::Ext; start_host();']
|
|
|
|
" Collect registered perl plugins into args
|
|
let perl_plugins = remote#host#PluginsForHost(a:host.name)
|
|
for plugin in perl_plugins
|
|
call add(args, plugin.path)
|
|
endfor
|
|
|
|
return provider#Poll(args, a:host.orig_name, '$NVIM_PERL_LOG_FILE')
|
|
endfunction
|
|
|
|
function! provider#perl#Call(method, args) abort
|
|
if s:err != ''
|
|
echoerr s:err
|
|
return
|
|
endif
|
|
|
|
if !exists('s:host')
|
|
try
|
|
let s:host = remote#host#Require('perl')
|
|
catch
|
|
let s:err = v:exception
|
|
echohl WarningMsg
|
|
echomsg v:exception
|
|
echohl None
|
|
return
|
|
endtry
|
|
endif
|
|
return call('rpcrequest', insert(insert(a:args, 'perl_'.a:method), s:host))
|
|
endfunction
|
|
|
|
let s:err = ''
|
|
let s:prog = provider#perl#Detect()
|
|
let g:loaded_perl_provider = empty(s:prog) ? 1 : 2
|
|
|
|
if g:loaded_perl_provider != 2
|
|
let s:err = 'Cannot find perl or the required perl module'
|
|
endif
|
|
|
|
call remote#host#RegisterPlugin('perl-provider', 'perl', [])
|