ruby.vim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. " The Ruby provider helper
  2. if exists('g:loaded_ruby_provider')
  3. finish
  4. endif
  5. let g:loaded_ruby_provider = 1
  6. function! provider#ruby#Detect() abort
  7. let e = empty(s:prog) ? 'missing ruby or ruby-host' : ''
  8. return [s:prog, e]
  9. endfunction
  10. function! provider#ruby#Prog() abort
  11. return s:prog
  12. endfunction
  13. function! provider#ruby#Require(host) abort
  14. let prog = provider#ruby#Prog()
  15. let ruby_plugins = remote#host#PluginsForHost(a:host.name)
  16. for plugin in ruby_plugins
  17. let prog .= " " . shellescape(plugin.path)
  18. endfor
  19. return provider#Poll(prog, a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
  20. endfunction
  21. function! provider#ruby#Call(method, args) abort
  22. if s:err != ''
  23. echoerr s:err
  24. return
  25. endif
  26. if !exists('s:host')
  27. try
  28. let s:host = remote#host#Require('legacy-ruby-provider')
  29. catch
  30. let s:err = v:exception
  31. echohl WarningMsg
  32. echomsg v:exception
  33. echohl None
  34. return
  35. endtry
  36. endif
  37. return call('rpcrequest', insert(insert(a:args, 'ruby_'.a:method), s:host))
  38. endfunction
  39. function! s:detect()
  40. if exists("g:ruby_host_prog")
  41. return expand(g:ruby_host_prog, v:true)
  42. elseif has('win32')
  43. return exepath('neovim-ruby-host.bat')
  44. else
  45. let p = exepath('neovim-ruby-host')
  46. if empty(p)
  47. return ''
  48. endif
  49. " neovim-ruby-host could be an rbenv shim for another Ruby version.
  50. call system(p)
  51. return v:shell_error ? '' : p
  52. end
  53. endfunction
  54. let s:err = ''
  55. let s:prog = s:detect()
  56. let s:plugin_path = expand('<sfile>:p:h') . '/script_host.rb'
  57. let g:loaded_ruby_provider = empty(s:prog) ? 1 : 2
  58. if g:loaded_ruby_provider != 2
  59. let s:err = 'Cannot find the neovim RubyGem. Try :checkhealth'
  60. endif
  61. call remote#host#RegisterClone('legacy-ruby-provider', 'ruby')
  62. call remote#host#RegisterPlugin('legacy-ruby-provider', s:plugin_path, [])