diff options
Diffstat (limited to 'runtime/autoload/provider/ruby.vim')
-rw-r--r-- | runtime/autoload/provider/ruby.vim | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim index aad8c09d28..3b4c6c4839 100644 --- a/runtime/autoload/provider/ruby.vim +++ b/runtime/autoload/provider/ruby.vim @@ -1,34 +1,71 @@ " The Ruby provider helper -if exists('s:loaded_ruby_provider') +if exists('g:loaded_ruby_provider') finish endif +let g:loaded_ruby_provider = 1 -let s:loaded_ruby_provider = 1 +function! provider#ruby#Detect() abort + return s:prog +endfunction + +function! provider#ruby#Prog() abort + return s:prog +endfunction function! provider#ruby#Require(host) abort - " Collect registered Ruby plugins into args - let args = [] + let prog = provider#ruby#Prog() let ruby_plugins = remote#host#PluginsForHost(a:host.name) for plugin in ruby_plugins - call add(args, plugin.path) + let prog .= " " . shellescape(plugin.path) endfor - try - let channel_id = rpcstart(provider#ruby#Prog(), args) + return provider#Poll(prog, a:host.orig_name, '$NVIM_RUBY_LOG_FILE') +endfunction - if rpcrequest(channel_id, 'poll') == 'ok' - return channel_id - endif - catch - echomsg v:throwpoint - echomsg v:exception - endtry +function! provider#ruby#Call(method, args) abort + if s:err != '' + echoerr s:err + return + endif - throw remote#host#LoadErrorForHost(a:host.orig_name, - \ '$NVIM_RUBY_LOG_FILE') + if !exists('s:host') + try + let s:host = remote#host#Require('legacy-ruby-provider') + catch + let s:err = v:exception + echohl WarningMsg + echomsg v:exception + echohl None + return + endtry + endif + return call('rpcrequest', insert(insert(a:args, 'ruby_'.a:method), s:host)) endfunction -function! provider#ruby#Prog() abort - return 'neovim-ruby-host' +function! s:detect() + if exists("g:ruby_host_prog") + return expand(g:ruby_host_prog) + elseif has('win32') + return exepath('neovim-ruby-host.bat') + else + let p = exepath('neovim-ruby-host') + if empty(p) + return '' + endif + " neovim-ruby-host could be an rbenv shim for another Ruby version. + call system(p) + return v:shell_error ? '' : p + end endfunction + +let s:err = '' +let s:prog = s:detect() +let s:plugin_path = expand('<sfile>:p:h') . '/script_host.rb' + +if empty(s:prog) + let s:err = 'Cannot find the neovim RubyGem. Try :checkhealth' +endif + +call remote#host#RegisterClone('legacy-ruby-provider', 'ruby') +call remote#host#RegisterPlugin('legacy-ruby-provider', s:plugin_path, []) |