fix(remote): report on missing wait commands, typecheck lua results

Clean up lint errors, too
This commit is contained in:
Charlie Groves 2022-03-03 16:33:27 -05:00
parent e095a868cb
commit 29c3632285
4 changed files with 37 additions and 34 deletions

View File

@ -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 Vim supports additional functionality in clientserver that's not yet
implemented in Nvim. In particular, none of the 'wait' variants are supported implemented in Nvim. In particular, none of the 'wait' variants are supported

View File

@ -638,56 +638,39 @@ end
function vim._cs_remote(rcid, args) function vim._cs_remote(rcid, args)
local f_silent = false local f_silent = false
local f_wait = false
local f_tab = false local f_tab = false
local subcmd = string.sub(args[1],10) local subcmd = string.sub(args[1],10)
if subcmd == '' then if subcmd == 'tab' then
-- no flags to set
elseif subcmd == 'tab' then
f_tab = true f_tab = true
elseif subcmd == 'silent' then elseif subcmd == 'silent' then
f_silent = true f_silent = true
elseif subcmd == 'wait' then elseif subcmd == 'wait' or subcmd == 'wait-silent' or subcmd == 'tab-wait' or subcmd == 'tab-wait-silent' then
f_wait = true return { errmsg = 'E5600: Wait commands not yet implemented in nvim' }
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 elseif subcmd == 'tab-silent' then
f_tab = true f_tab = true
f_silent = true f_silent = true
elseif subcmd == 'tab-wait-silent' then
f_tab = true
f_wait = true
f_silent = true
elseif subcmd == 'send' then elseif subcmd == 'send' then
if rcid == 0 then if rcid == 0 then
vim.cmd('echoerr "E247: Remote server does not exist. Send failed."') return { errmsg = 'E247: Remote server does not exist. Send failed.' }
return
end end
vim.fn.rpcrequest(rcid, 'nvim_input', args[2]) vim.fn.rpcrequest(rcid, 'nvim_input', args[2])
return { should_exit = true, tabbed = false } return { should_exit = true, tabbed = false }
elseif subcmd == 'expr' then elseif subcmd == 'expr' then
if rcid == 0 then if rcid == 0 then
vim.cmd('echoerr "E247: Remote server does not exist. Send expression failed."') return { errmsg = 'E247: Remote server does not exist. Send expression failed.' }
return
end end
vim.fn.rpcrequest(rcid, 'nvim_eval', args[2]) print(vim.fn.rpcrequest(rcid, 'nvim_eval', args[2]))
return { should_exit = true, tabbed = false } return { should_exit = true, tabbed = false }
else elseif subcmd ~= '' then
vim.cmd('echoerr "Unknown option argument: ' .. args[1] .. '"') return { errmsg='Unknown option argument: ' .. args[1] }
return
end end
if rcid == 0 then if rcid == 0 then
if not f_silent then if not f_silent then
vim.cmd('echohl WarningMsg | echomsg "E247: Remote server does not exist. Editing locally" | echohl None') vim.cmd('echohl WarningMsg | echomsg "E247: Remote server does not exist. Editing locally" | echohl None')
end end
should_exit = false
else else
local command = {} local command = {}
if f_tab then table.insert(command, 'tab') end if f_tab then table.insert(command, 'tab') end

View File

@ -816,8 +816,10 @@ static void handle_remote_client(mparm_T *params, int remote_args,
rvobj.type = kObjectTypeDictionary; rvobj.type = kObjectTypeDictionary;
CallbackReader on_data = CALLBACK_READER_INIT; CallbackReader on_data = CALLBACK_READER_INIT;
const char *error = NULL; const char *error = NULL;
uint64_t rc_id = server_addr == NULL ? 0 : channel_connect(false, uint64_t rc_id = 0;
server_addr, true, on_data, 50, &error); if (server_addr != NULL) {
rc_id = channel_connect(false, server_addr, true, on_data, 50, &error);
}
Boolean should_exit = true; Boolean should_exit = true;
Boolean tabbed; Boolean tabbed;
@ -848,17 +850,33 @@ static void handle_remote_client(mparm_T *params, int remote_args,
rvobj.data.dictionary = o.data.dictionary; rvobj.data.dictionary = o.data.dictionary;
} else { } else {
mch_errmsg("vim._cs_remote returned unexpected value\n"); 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++) { for (size_t i = 0; i < rvobj.data.dictionary.size ; i++) {
if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) { if (strcmp(rvobj.data.dictionary.items[i].key.data, "errmsg") == 0) {
// should we check items[i].value.type here? 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; tabbed = rvobj.data.dictionary.items[i].value.data.boolean;
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "should_exit") == 0) { } 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; should_exit = rvobj.data.dictionary.items[i].value.data.boolean;
} }
} }
api_free_object(o);
if (should_exit) { if (should_exit) {
os_exit(0); os_exit(0);

View File

@ -9,7 +9,6 @@ local insert = helpers.insert
local meths = helpers.meths local meths = helpers.meths
local new_argv = helpers.new_argv local new_argv = helpers.new_argv
local neq = helpers.neq local neq = helpers.neq
local run = helpers.run
local set_session = helpers.set_session local set_session = helpers.set_session
local spawn = helpers.spawn local spawn = helpers.spawn
local tmpname = helpers.tmpname local tmpname = helpers.tmpname
@ -38,7 +37,7 @@ describe('Remote', function()
server:close() server:close()
end) end)
function run_remote(...) local function run_remote(...)
set_session(server) set_session(server)
local addr = funcs.serverlist()[1] local addr = funcs.serverlist()[1]
local client_argv = new_argv({args={'--server', addr, ...}}) 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 -- 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 -- the event loop. If the server event loop is blocked, it can't process
-- our incoming --remote calls. -- our incoming --remote calls.
local client_starter = clear() clear()
local bogus_job_id = funcs.jobstart(bogus_argv) local bogus_job_id = funcs.jobstart(bogus_argv)
eq({2}, funcs.jobwait({bogus_job_id})) eq({2}, funcs.jobwait({bogus_job_id}))
end end
@ -136,5 +135,8 @@ describe('Remote', function()
it('expr without server', function() it('expr without server', function()
run_and_check_exit_code('--remote-expr', 'setline(1, "Yo")') run_and_check_exit_code('--remote-expr', 'setline(1, "Yo")')
end) end)
it('wait subcommand', function()
run_and_check_exit_code('--remote-wait', fname)
end)
end) end)
end) end)