Skip to content

Commit

Permalink
fix(remote): report on missing wait commands, typecheck lua results
Browse files Browse the repository at this point in the history
Clean up lint errors, too
  • Loading branch information
groves committed Mar 11, 2022
1 parent e095a86 commit 29c3632
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion runtime/doc/remote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 8 additions & 25 deletions runtime/lua/vim/_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions src/nvim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions test/functional/core/remote_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ...}})
Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 29c3632

Please sign in to comment.