robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local M ={} 2local s_err ---@type string? 3local s_host ---@type integer? 4 5--- @param host { name: string, orig_name: string } 6--- @return integer 7function M . require ( host ) 8local prog =M . detect () 9local args ={ prog } 10local ruby_plugins =vim . fn [ 'remote#host#PluginsForHost' ]( host . name ) ---@type any 11 12---@param plugin any 13for _ , plugin in ipairs ( ruby_plugins ) do 14table . insert ( args , plugin . path ) 15end 16 17return vim . fn [ 'provider#Poll' ]( args , host . orig_name , '$NVIM_RUBY_LOG_FILE' ) 18end 19 20---@param method string 21---@param args any[] 22function M . call ( method , args ) 23if s_err then 24return 25end 26 27if not s_host then 28local ok , result =pcall ( vim . fn [ 'remote#host#Require' ], 'legacy-ruby-provider' ) ---@type any, any 29if not ok then 30s_err =result 31vim . api . nvim_echo ( { { result , 'WarningMsg' } } , true ) 32return 33end 34--- @cast result integer 35s_host =result 36end 37 38return vim . fn . rpcrequest ( s_host , 'ruby_' .. method , unpack ( args )) 39end 40 41function M . detect () 42local prog ---@type string 43if vim . g . ruby_host_prog then 44prog =vim . fn . expand ( vim . g . ruby_host_prog , true ) 45elseif vim . fn . has ( 'win32' ) == 1 then 46prog =vim . fn . exepath ( 'neovim-ruby-host.bat' ) 47else 48local p =vim . fn . exepath ( 'neovim-ruby-host' ) 49if p == '' then 50prog ='' 51else 52-- neovim-ruby-host could be an rbenv shim for another Ruby version. 53local result =vim . system ( { p } ): wait () 54prog =result . code ~= 0 and '' or p 55end 56end 57local err =prog == '' and 'missing ruby or ruby-host' or '' 58return prog , err 59end 60 61--- @param plugin_path string 62function M . start ( plugin_path ) 63vim . fn [ 'remote#host#RegisterClone' ]( 'legacy-ruby-provider' , 'ruby' ) 64vim . fn [ 'remote#host#RegisterPlugin' ]( 'legacy-ruby-provider' , plugin_path , {} ) 65end 66 67return M