mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 20:18:32 +00:00
channel: Implement the 'channel_send_call' function
This function is used to send RPC calls to clients. In contrast to `channel_send_event`, this function will block until the client sends a response(But it will continue processing requests from that client). The RPC call stack has a maximum depth of 20.
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
#include "nvim/os/time.h"
|
||||
#include "nvim/os/channel.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/os/msgpack_rpc.h"
|
||||
|
||||
#define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
|
||||
|
||||
@@ -6453,6 +6454,7 @@ static struct fst {
|
||||
{"searchpair", 3, 7, f_searchpair},
|
||||
{"searchpairpos", 3, 7, f_searchpairpos},
|
||||
{"searchpos", 1, 4, f_searchpos},
|
||||
{"send_call", 3, 3, f_send_call},
|
||||
{"send_event", 3, 3, f_send_event},
|
||||
{"setbufvar", 3, 3, f_setbufvar},
|
||||
{"setcmdpos", 1, 1, f_setcmdpos},
|
||||
@@ -12525,6 +12527,47 @@ do_searchpair (
|
||||
return retval;
|
||||
}
|
||||
|
||||
// "send_call()" function
|
||||
static void f_send_call(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
rettv->v_type = VAR_NUMBER;
|
||||
rettv->vval.v_number = 0;
|
||||
|
||||
if (check_restricted() || check_secure()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (argvars[0].v_type != VAR_NUMBER || argvars[0].vval.v_number <= 0) {
|
||||
EMSG2(_(e_invarg2), "Channel id must be a positive integer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (argvars[1].v_type != VAR_STRING) {
|
||||
EMSG2(_(e_invarg2), "Method name must be a string");
|
||||
return;
|
||||
}
|
||||
|
||||
bool errored;
|
||||
Object result;
|
||||
if (!channel_send_call((uint64_t)argvars[0].vval.v_number,
|
||||
(char *)argvars[1].vval.v_string,
|
||||
vim_to_object(&argvars[2]),
|
||||
&result,
|
||||
&errored)) {
|
||||
EMSG2(_(e_invarg2), "Channel doesn't exist");
|
||||
return;
|
||||
}
|
||||
|
||||
Error conversion_error = {.set = false};
|
||||
if (errored || !object_to_vim(result, rettv, &conversion_error)) {
|
||||
EMSG(errored ?
|
||||
result.data.string.data :
|
||||
_("Error converting the call result"));
|
||||
}
|
||||
|
||||
msgpack_rpc_free_object(result);
|
||||
}
|
||||
|
||||
// "send_event()" function
|
||||
static void f_send_event(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
|
Reference in New Issue
Block a user