diff options
author | Charlie Groves <charlie.groves@gmail.com> | 2022-02-16 17:11:50 -0500 |
---|---|---|
committer | Charlie Groves <charlie.groves@gmail.com> | 2022-03-11 11:16:46 -0500 |
commit | 5862176764c7a86d5fdd2685122810e14a3d5b02 (patch) | |
tree | a6780e13e4b157ecc9062f1b4e54a442098548ff /runtime/lua/vim/_editor.lua | |
parent | 76769b8a1f5b34f4b0cef389597cec2796ca91b7 (diff) | |
download | rneovim-5862176764c7a86d5fdd2685122810e14a3d5b02.tar.gz rneovim-5862176764c7a86d5fdd2685122810e14a3d5b02.tar.bz2 rneovim-5862176764c7a86d5fdd2685122810e14a3d5b02.zip |
feat(remote): add basic --remote support
This is starting from @geekodour's work at
https://github.com/neovim/neovim/pull/8326
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r-- | runtime/lua/vim/_editor.lua | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 3136e36043..5f3d66e108 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -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') |