mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00

Instead of deciding provider status in eval_has_provider, move the decision to the provider Vim scripts. Previously, provider loading worked as follows: 1. eval_has_provider() verified provider availability by searching for the provider#providername#Call function and cached this verificaion as a static variable for some providers 2. providers short-circuited on loading to prevent the definition of the Call function (with the exception of the node provider that did not) This commit changes the expected interface between nvim and its providers to facilitate provider reloading, by splitting the verification of the provider from the availability of the Call function. eval_has_provider() now checks for a provider#providername#enabled variable. It is up to the provider script to set this to 0 or 1 accordingly. eval_call_provider() remains unchanged. All providers hosting a Call function were updated to respect this. The clipboard provider now has a Reload function to reload the provider.
75 lines
1.7 KiB
VimL
75 lines
1.7 KiB
VimL
" The Ruby provider helper
|
|
if exists('g:loaded_ruby_provider')
|
|
finish
|
|
endif
|
|
let g:loaded_ruby_provider = 1
|
|
|
|
function! provider#ruby#Detect() abort
|
|
return s:prog
|
|
endfunction
|
|
let g:provider#ruby#enabled = 0
|
|
|
|
function! provider#ruby#Prog() abort
|
|
return s:prog
|
|
endfunction
|
|
|
|
function! provider#ruby#Require(host) abort
|
|
let prog = provider#ruby#Prog()
|
|
let ruby_plugins = remote#host#PluginsForHost(a:host.name)
|
|
|
|
for plugin in ruby_plugins
|
|
let prog .= " " . shellescape(plugin.path)
|
|
endfor
|
|
|
|
return provider#Poll(prog, a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
|
|
endfunction
|
|
|
|
function! provider#ruby#Call(method, args) abort
|
|
if s:err != ''
|
|
echoerr s:err
|
|
return
|
|
endif
|
|
|
|
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! 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'
|
|
else
|
|
let g:provider#ruby#enabled = 1
|
|
endif
|
|
|
|
call remote#host#RegisterClone('legacy-ruby-provider', 'ruby')
|
|
call remote#host#RegisterPlugin('legacy-ruby-provider', s:plugin_path, [])
|