mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 14:58:18 +00:00
api: Change type of event data to Object
from typval_T
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
#include "nvim/os/rstream_defs.h"
|
#include "nvim/os/rstream_defs.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os/channel.h"
|
#include "nvim/os/channel.h"
|
||||||
|
#include "nvim/api/private/helpers.h"
|
||||||
|
|
||||||
#define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
|
#define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
|
||||||
|
|
||||||
@@ -12555,7 +12556,7 @@ static void f_send_event(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
if (!channel_send_event((uint64_t)argvars[0].vval.v_number,
|
if (!channel_send_event((uint64_t)argvars[0].vval.v_number,
|
||||||
(char *)argvars[1].vval.v_string,
|
(char *)argvars[1].vval.v_string,
|
||||||
&argvars[2])) {
|
vim_to_object(&argvars[2]))) {
|
||||||
EMSG2(_(e_invarg2), "Channel doesn't exist");
|
EMSG2(_(e_invarg2), "Channel doesn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -116,12 +116,13 @@ void channel_from_stream(uv_stream_t *stream)
|
|||||||
/// @param type The event type, an arbitrary string
|
/// @param type The event type, an arbitrary string
|
||||||
/// @param obj The event data
|
/// @param obj The event data
|
||||||
/// @return True if the data was sent successfully, false otherwise.
|
/// @return True if the data was sent successfully, false otherwise.
|
||||||
bool channel_send_event(uint64_t id, char *type, typval_T *data)
|
bool channel_send_event(uint64_t id, char *type, Object data)
|
||||||
{
|
{
|
||||||
Channel *channel = NULL;
|
Channel *channel = NULL;
|
||||||
|
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
if (!(channel = pmap_get(uint64_t)(channels, id))) {
|
if (!(channel = pmap_get(uint64_t)(channels, id))) {
|
||||||
|
msgpack_rpc_free_object(data);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
send_event(channel, type, data);
|
send_event(channel, type, data);
|
||||||
@@ -248,12 +249,12 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_event(Channel *channel, char *type, typval_T *data)
|
static void send_event(Channel *channel, char *type, Object data)
|
||||||
{
|
{
|
||||||
wstream_write(channel->data.streams.write, serialize_event(type, data));
|
wstream_write(channel->data.streams.write, serialize_event(type, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void broadcast_event(char *type, typval_T *data)
|
static void broadcast_event(char *type, Object data)
|
||||||
{
|
{
|
||||||
kvec_t(Channel *) subscribed;
|
kvec_t(Channel *) subscribed;
|
||||||
kv_init(subscribed);
|
kv_init(subscribed);
|
||||||
@@ -266,6 +267,7 @@ static void broadcast_event(char *type, typval_T *data)
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!kv_size(subscribed)) {
|
if (!kv_size(subscribed)) {
|
||||||
|
msgpack_rpc_free_object(data);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,18 +329,17 @@ static void close_cb(uv_handle_t *handle)
|
|||||||
free(handle);
|
free(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WBuffer *serialize_event(char *type, typval_T *data)
|
static WBuffer *serialize_event(char *type, Object data)
|
||||||
{
|
{
|
||||||
String event_type = {.size = strnlen(type, EVENT_MAXLEN), .data = type};
|
String event_type = {.size = strnlen(type, EVENT_MAXLEN), .data = type};
|
||||||
Object event_data = vim_to_object(data);
|
|
||||||
msgpack_packer packer;
|
msgpack_packer packer;
|
||||||
msgpack_packer_init(&packer, &msgpack_event_buffer, msgpack_sbuffer_write);
|
msgpack_packer_init(&packer, &msgpack_event_buffer, msgpack_sbuffer_write);
|
||||||
msgpack_rpc_notification(event_type, event_data, &packer);
|
msgpack_rpc_notification(event_type, data, &packer);
|
||||||
WBuffer *rv = wstream_new_buffer(xmemdup(msgpack_event_buffer.data,
|
WBuffer *rv = wstream_new_buffer(xmemdup(msgpack_event_buffer.data,
|
||||||
msgpack_event_buffer.size),
|
msgpack_event_buffer.size),
|
||||||
msgpack_event_buffer.size,
|
msgpack_event_buffer.size,
|
||||||
free);
|
free);
|
||||||
msgpack_rpc_free_object(event_data);
|
msgpack_rpc_free_object(data);
|
||||||
msgpack_sbuffer_clear(&msgpack_event_buffer);
|
msgpack_sbuffer_clear(&msgpack_event_buffer);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
#define NVIM_OS_CHANNEL_H
|
#define NVIM_OS_CHANNEL_H
|
||||||
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
#include <msgpack.h>
|
|
||||||
|
|
||||||
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
#define EVENT_MAXLEN 512
|
#define EVENT_MAXLEN 512
|
||||||
|
Reference in New Issue
Block a user