From 29c36322857b37263b07eb1301d71ccd8a2ae044 Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Thu, 3 Mar 2022 16:33:27 -0500 Subject: [PATCH] fix(remote): report on missing wait commands, typecheck lua results Clean up lint errors, too --- runtime/doc/remote.txt | 2 +- runtime/lua/vim/_editor.lua | 33 +++++++--------------------- src/nvim/main.c | 28 ++++++++++++++++++----- test/functional/core/remote_spec.lua | 8 ++++--- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/runtime/doc/remote.txt b/runtime/doc/remote.txt index dd5d44387d..b8991be738 100644 --- a/runtime/doc/remote.txt +++ b/runtime/doc/remote.txt @@ -83,7 +83,7 @@ You can not put options there! ============================================================================== -2. Missing functionality *clientserver-missing* +2. Missing functionality *E5600* *clientserver-missing* Vim supports additional functionality in clientserver that's not yet implemented in Nvim. In particular, none of the 'wait' variants are supported diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 869a2706ac..030c3b40e8 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -638,56 +638,39 @@ end function vim._cs_remote(rcid, args) local f_silent = false - local f_wait = false local f_tab = false local subcmd = string.sub(args[1],10) - if subcmd == '' then - -- no flags to set - elseif subcmd == 'tab' then + if 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 == 'wait' or subcmd == 'wait-silent' or subcmd == 'tab-wait' or subcmd == 'tab-wait-silent' then + return { errmsg = 'E5600: Wait commands not yet implemented in nvim' } 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 if rcid == 0 then - vim.cmd('echoerr "E247: Remote server does not exist. Send failed."') - return + return { errmsg = 'E247: Remote server does not exist. Send failed.' } end vim.fn.rpcrequest(rcid, 'nvim_input', args[2]) return { should_exit = true, tabbed = false } elseif subcmd == 'expr' then if rcid == 0 then - vim.cmd('echoerr "E247: Remote server does not exist. Send expression failed."') - return + return { errmsg = 'E247: Remote server does not exist. Send expression failed.' } end - vim.fn.rpcrequest(rcid, 'nvim_eval', args[2]) + print(vim.fn.rpcrequest(rcid, 'nvim_eval', args[2])) return { should_exit = true, tabbed = false } - else - vim.cmd('echoerr "Unknown option argument: ' .. args[1] .. '"') - return + elseif subcmd ~= '' then + return { errmsg='Unknown option argument: ' .. args[1] } end if rcid == 0 then if not f_silent then vim.cmd('echohl WarningMsg | echomsg "E247: Remote server does not exist. Editing locally" | echohl None') end - should_exit = false else local command = {} if f_tab then table.insert(command, 'tab') end diff --git a/src/nvim/main.c b/src/nvim/main.c index a3588ac5df..eb60d51b9b 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -816,8 +816,10 @@ static void handle_remote_client(mparm_T *params, int remote_args, rvobj.type = kObjectTypeDictionary; CallbackReader on_data = CALLBACK_READER_INIT; const char *error = NULL; - uint64_t rc_id = server_addr == NULL ? 0 : channel_connect(false, - server_addr, true, on_data, 50, &error); + uint64_t rc_id = 0; + if (server_addr != NULL) { + rc_id = channel_connect(false, server_addr, true, on_data, 50, &error); + } Boolean should_exit = true; Boolean tabbed; @@ -848,17 +850,33 @@ static void handle_remote_client(mparm_T *params, int remote_args, rvobj.data.dictionary = o.data.dictionary; } else { mch_errmsg("vim._cs_remote returned unexpected value\n"); - os_exit(3); + os_exit(2); } for (size_t i = 0; i < rvobj.data.dictionary.size ; i++) { - if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) { - // should we check items[i].value.type here? + if (strcmp(rvobj.data.dictionary.items[i].key.data, "errmsg") == 0) { + if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) { + mch_errmsg("vim._cs_remote returned an unexpected type for 'errmsg'\n"); + os_exit(2); + } + mch_errmsg(rvobj.data.dictionary.items[i].value.data.string.data); + mch_errmsg("\n"); + os_exit(2); + } else if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) { + if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) { + mch_errmsg("vim._cs_remote returned an unexpected type for 'tabbed'\n"); + os_exit(2); + } tabbed = rvobj.data.dictionary.items[i].value.data.boolean; } else if (strcmp(rvobj.data.dictionary.items[i].key.data, "should_exit") == 0) { + if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) { + mch_errmsg("vim._cs_remote returned an unexpected type for 'should_exit'\n"); + os_exit(2); + } should_exit = rvobj.data.dictionary.items[i].value.data.boolean; } } + api_free_object(o); if (should_exit) { os_exit(0); diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index e86d15ec69..602a5a71eb 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -9,7 +9,6 @@ local insert = helpers.insert local meths = helpers.meths local new_argv = helpers.new_argv local neq = helpers.neq -local run = helpers.run local set_session = helpers.set_session local spawn = helpers.spawn local tmpname = helpers.tmpname @@ -38,7 +37,7 @@ describe('Remote', function() server:close() end) - function run_remote(...) + local function run_remote(...) set_session(server) local addr = funcs.serverlist()[1] local client_argv = new_argv({args={'--server', addr, ...}}) @@ -121,7 +120,7 @@ describe('Remote', function() -- to wait for the remote instance to exit and calling jobwait blocks -- the event loop. If the server event loop is blocked, it can't process -- our incoming --remote calls. - local client_starter = clear() + clear() local bogus_job_id = funcs.jobstart(bogus_argv) eq({2}, funcs.jobwait({bogus_job_id})) end @@ -136,5 +135,8 @@ describe('Remote', function() it('expr without server', function() run_and_check_exit_code('--remote-expr', 'setline(1, "Yo")') end) + it('wait subcommand', function() + run_and_check_exit_code('--remote-wait', fname) + end) end) end)