mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(main): separate connection code from --remote execution code
This commit is contained in:
parent
ab456bc304
commit
3a12737e6c
@ -1997,9 +1997,8 @@ Array nvim_get_proc_children(Integer pid, Error *err)
|
||||
DLOG("fallback to vim._os_proc_children()");
|
||||
Array a = ARRAY_DICT_INIT;
|
||||
ADD(a, INTEGER_OBJ(pid));
|
||||
String s = cstr_to_string("return vim._os_proc_children(...)");
|
||||
String s = STATIC_CSTR_AS_STRING("return vim._os_proc_children(...)");
|
||||
Object o = nlua_exec(s, a, err);
|
||||
api_free_string(s);
|
||||
api_free_array(a);
|
||||
if (o.type == kObjectTypeArray) {
|
||||
rvobj = o.data.array;
|
||||
|
@ -269,7 +269,7 @@ int main(int argc, char **argv)
|
||||
|
||||
server_init(params.listen_addr);
|
||||
if (params.remote) {
|
||||
handle_remote_client(¶ms, params.remote,
|
||||
remote_request(¶ms, params.remote,
|
||||
params.server_addr, argc, argv);
|
||||
}
|
||||
|
||||
@ -807,19 +807,32 @@ static void init_locale(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static uint64_t server_connect(char *server_addr, const char **errmsg)
|
||||
{
|
||||
if (server_addr == NULL) {
|
||||
*errmsg = "no address specified";
|
||||
return 0;
|
||||
}
|
||||
CallbackReader on_data = CALLBACK_READER_INIT;
|
||||
const char *error = NULL;
|
||||
bool is_tcp = strrchr(server_addr, ':') ? true : false;
|
||||
// connected to channel
|
||||
uint64_t chan = channel_connect(is_tcp, server_addr, true, on_data, 50, &error);
|
||||
if (error) {
|
||||
*errmsg = error;
|
||||
return 0;
|
||||
}
|
||||
return chan;
|
||||
}
|
||||
|
||||
/// Handle remote subcommands
|
||||
static void handle_remote_client(mparm_T *params, int remote_args,
|
||||
static void remote_request(mparm_T *params, int remote_args,
|
||||
char *server_addr, int argc, char **argv)
|
||||
{
|
||||
Object rvobj = OBJECT_INIT;
|
||||
rvobj.data.dictionary = (Dictionary)ARRAY_DICT_INIT;
|
||||
rvobj.type = kObjectTypeDictionary;
|
||||
CallbackReader on_data = CALLBACK_READER_INIT;
|
||||
const char *connect_error = NULL;
|
||||
uint64_t rc_id = 0;
|
||||
if (server_addr != NULL) {
|
||||
rc_id = channel_connect(false, server_addr, true, on_data, 50, &connect_error);
|
||||
}
|
||||
uint64_t chan = server_connect(server_addr, &connect_error);
|
||||
Object rvobj = OBJECT_INIT;
|
||||
|
||||
int t_argc = remote_args;
|
||||
Array args = ARRAY_DICT_INIT;
|
||||
@ -831,7 +844,7 @@ static void handle_remote_client(mparm_T *params, int remote_args,
|
||||
|
||||
Error err = ERROR_INIT;
|
||||
Array a = ARRAY_DICT_INIT;
|
||||
ADD(a, INTEGER_OBJ((int)rc_id));
|
||||
ADD(a, INTEGER_OBJ((int)chan));
|
||||
ADD(a, CSTR_TO_OBJ(server_addr));
|
||||
ADD(a, CSTR_TO_OBJ(connect_error));
|
||||
ADD(a, ARRAY_OBJ(args));
|
||||
@ -892,6 +905,7 @@ static void handle_remote_client(mparm_T *params, int remote_args,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Decides whether text (as opposed to commands) will be read from stdin.
|
||||
/// @see EDIT_STDIN
|
||||
static bool edit_stdin(bool explicit, mparm_T *parmp)
|
||||
|
Loading…
Reference in New Issue
Block a user