mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 16:28:17 +00:00
fix(remote): respect silent in error reporting
This commit is contained in:
@@ -636,12 +636,24 @@ function vim.pretty_print(...)
|
|||||||
return ...
|
return ...
|
||||||
end
|
end
|
||||||
|
|
||||||
function vim._cs_remote(rcid, args)
|
function vim._cs_remote(rcid, server_addr, connect_error, args)
|
||||||
|
local function connection_failure_errmsg(consequence)
|
||||||
|
local explanation
|
||||||
|
if server_addr == '' then
|
||||||
|
explanation = "No server specified with --server"
|
||||||
|
else
|
||||||
|
explanation = "Failed to connect to '" .. server_addr .. "'"
|
||||||
|
if connect_error ~= "" then
|
||||||
|
explanation = explanation .. ": " .. connect_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "E247: " .. explanation .. ". " .. consequence
|
||||||
|
end
|
||||||
|
|
||||||
local f_silent = false
|
local f_silent = 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 == 'tab' then
|
if subcmd == 'tab' then
|
||||||
f_tab = true
|
f_tab = true
|
||||||
elseif subcmd == 'silent' then
|
elseif subcmd == 'silent' then
|
||||||
@@ -653,13 +665,13 @@ function vim._cs_remote(rcid, args)
|
|||||||
f_silent = true
|
f_silent = true
|
||||||
elseif subcmd == 'send' then
|
elseif subcmd == 'send' then
|
||||||
if rcid == 0 then
|
if rcid == 0 then
|
||||||
return { errmsg = 'E247: Remote server does not exist. Send failed.' }
|
return { errmsg = connection_failure_errmsg('Send failed.') }
|
||||||
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
|
||||||
return { errmsg = 'E247: Remote server does not exist. Send expression failed.' }
|
return { errmsg = connection_failure_errmsg('Send expression failed.') }
|
||||||
end
|
end
|
||||||
print(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 }
|
||||||
@@ -669,7 +681,7 @@ function vim._cs_remote(rcid, args)
|
|||||||
|
|
||||||
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.notify(connection_failure_errmsg("Editing locally"), vim.log.levels.WARN)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local command = {}
|
local command = {}
|
||||||
|
@@ -815,17 +815,10 @@ static void handle_remote_client(mparm_T *params, int remote_args,
|
|||||||
rvobj.data.dictionary = (Dictionary)ARRAY_DICT_INIT;
|
rvobj.data.dictionary = (Dictionary)ARRAY_DICT_INIT;
|
||||||
rvobj.type = kObjectTypeDictionary;
|
rvobj.type = kObjectTypeDictionary;
|
||||||
CallbackReader on_data = CALLBACK_READER_INIT;
|
CallbackReader on_data = CALLBACK_READER_INIT;
|
||||||
const char *error = NULL;
|
const char *connect_error = NULL;
|
||||||
uint64_t rc_id = 0;
|
uint64_t rc_id = 0;
|
||||||
if (server_addr != NULL) {
|
if (server_addr != NULL) {
|
||||||
rc_id = channel_connect(false, server_addr, true, on_data, 50, &error);
|
rc_id = channel_connect(false, server_addr, true, on_data, 50, &connect_error);
|
||||||
}
|
|
||||||
if (error) {
|
|
||||||
mch_msg("Failed to connect to server ");
|
|
||||||
mch_msg(server_addr);
|
|
||||||
mch_msg("\nReason: ");
|
|
||||||
mch_msg(error);
|
|
||||||
mch_msg("Continuing with remote command in case we can execute locally\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int t_argc = remote_args;
|
int t_argc = remote_args;
|
||||||
@@ -839,6 +832,8 @@ static void handle_remote_client(mparm_T *params, int remote_args,
|
|||||||
Error err = ERROR_INIT;
|
Error err = ERROR_INIT;
|
||||||
Array a = ARRAY_DICT_INIT;
|
Array a = ARRAY_DICT_INIT;
|
||||||
ADD(a, INTEGER_OBJ((int)rc_id));
|
ADD(a, INTEGER_OBJ((int)rc_id));
|
||||||
|
ADD(a, CSTR_TO_OBJ(server_addr));
|
||||||
|
ADD(a, CSTR_TO_OBJ(connect_error));
|
||||||
ADD(a, ARRAY_OBJ(args));
|
ADD(a, ARRAY_OBJ(args));
|
||||||
String s = cstr_to_string("return vim._cs_remote(...)");
|
String s = cstr_to_string("return vim._cs_remote(...)");
|
||||||
Object o = nlua_exec(s, a, &err);
|
Object o = nlua_exec(s, a, &err);
|
||||||
|
Reference in New Issue
Block a user