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