feat(remote): add basic --remote support

This is starting from @geekodour's work at
https://github.com/neovim/neovim/pull/8326
This commit is contained in:
Charlie Groves
2022-02-16 17:11:50 -05:00
parent 76769b8a1f
commit 5862176764
4 changed files with 154 additions and 1 deletions

View File

@@ -636,6 +636,78 @@ function vim.pretty_print(...)
return ...
end
local function __rpcrequest(...)
return vim.api.nvim_call_function("rpcrequest", {...})
end
function vim._cs_remote(rcid, args)
local f_silent = false
local f_wait = false
local f_tab = false
local should_exit = true
local command = 'edit '
local subcmd = string.sub(args[1],10)
if subcmd == '' then
-- no flags to set
elseif subcmd == 'tab' then
f_tab = true
elseif subcmd == 'silent' then
f_silent = true
elseif subcmd == 'wait' then
f_wait = true
elseif subcmd == 'wait-silent' then
f_wait = true
f_silent = true
elseif subcmd == 'tab-wait' then
f_tab = true
f_wait = true
elseif subcmd == 'tab-silent' then
f_tab = true
f_silent = true
elseif subcmd == 'tab-wait-silent' then
f_tab = true
f_wait = true
f_silent = true
elseif subcmd == 'send' then
__rpcrequest(rcid, 'nvim_input', args[2])
return { should_exit = should_exit, tabbed = f_tab, files = 0 }
-- should we show warning if --server doesn't exist in --send and --expr?
elseif subcmd == 'expr' then
local res = __rpcrequest(rcid, 'vim_eval', args[2])
print(res)
return { should_exit = should_exit, tabbed = f_tab, files = 0 }
else
print('--remote subcommand not found')
end
table.remove(args,1)
if not f_silent and rcid == 0 then
print('Remote server does not exist.')
end
if f_silent and rcid == 0 then
print('Remote server does not exist. starting new server')
should_exit = false
end
if f_tab then command = 'tabedit ' end
if rcid ~= 0 then
for _, key in ipairs(args) do
__rpcrequest(rcid, 'nvim_command', command .. key)
end
end
return {
should_exit = should_exit,
tabbed = f_tab,
files = table.getn(args)
}
end
require('vim._meta')