mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
API: Events: Return channel id from the API discover request
This refactors msgapck_rpc_{dipatch,call} to receive the channel id as argument. Now the discovery request returns the [id, metadata] array.
This commit is contained in:
parent
7a00caf7c4
commit
139c7ffdc7
@ -111,7 +111,7 @@ end
|
|||||||
output:write([[
|
output:write([[
|
||||||
};
|
};
|
||||||
|
|
||||||
void msgpack_rpc_dispatch(msgpack_object *req, msgpack_packer *res)
|
void msgpack_rpc_dispatch(uint64_t id, msgpack_object *req, msgpack_packer *res)
|
||||||
{
|
{
|
||||||
Error error = { .set = false };
|
Error error = { .set = false };
|
||||||
uint64_t method_id = (uint32_t)req->via.array.ptr[2].via.u64;
|
uint64_t method_id = (uint32_t)req->via.array.ptr[2].via.u64;
|
||||||
@ -119,7 +119,9 @@ void msgpack_rpc_dispatch(msgpack_object *req, msgpack_packer *res)
|
|||||||
switch (method_id) {
|
switch (method_id) {
|
||||||
case 0:
|
case 0:
|
||||||
msgpack_pack_nil(res);
|
msgpack_pack_nil(res);
|
||||||
// The result is the `msgpack_metadata` byte array
|
// The result is the [channel_id, metadata] array
|
||||||
|
msgpack_pack_array(res, 2);
|
||||||
|
msgpack_pack_uint64(res, id);
|
||||||
msgpack_pack_raw(res, sizeof(msgpack_metadata));
|
msgpack_pack_raw(res, sizeof(msgpack_metadata));
|
||||||
msgpack_pack_raw_body(res, msgpack_metadata, sizeof(msgpack_metadata));
|
msgpack_pack_raw_body(res, msgpack_metadata, sizeof(msgpack_metadata));
|
||||||
return;
|
return;
|
||||||
|
@ -157,7 +157,7 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof)
|
|||||||
channel->proto.msgpack.sbuffer,
|
channel->proto.msgpack.sbuffer,
|
||||||
msgpack_sbuffer_write);
|
msgpack_sbuffer_write);
|
||||||
// Perform the call
|
// Perform the call
|
||||||
msgpack_rpc_call(&unpacked.data, &response);
|
msgpack_rpc_call(channel->id, &unpacked.data, &response);
|
||||||
wstream_write(channel->data.streams.write,
|
wstream_write(channel->data.streams.write,
|
||||||
xmemdup(channel->proto.msgpack.sbuffer->data,
|
xmemdup(channel->proto.msgpack.sbuffer->data,
|
||||||
channel->proto.msgpack.sbuffer->size),
|
channel->proto.msgpack.sbuffer->size),
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <msgpack.h>
|
#include <msgpack.h>
|
||||||
|
|
||||||
#include "nvim/os/msgpack_rpc.h"
|
#include "nvim/os/msgpack_rpc.h"
|
||||||
@ -52,7 +55,7 @@
|
|||||||
free(value.items); \
|
free(value.items); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res)
|
void msgpack_rpc_call(uint64_t id, msgpack_object *req, msgpack_packer *res)
|
||||||
{
|
{
|
||||||
// The initial response structure is the same no matter what happens,
|
// The initial response structure is the same no matter what happens,
|
||||||
// we set it up here
|
// we set it up here
|
||||||
@ -107,7 +110,7 @@ void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dispatch the message
|
// dispatch the message
|
||||||
msgpack_rpc_dispatch(req, res);
|
msgpack_rpc_dispatch(id, req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void msgpack_rpc_error(char *msg, msgpack_packer *res)
|
void msgpack_rpc_error(char *msg, msgpack_packer *res)
|
||||||
|
@ -11,9 +11,10 @@
|
|||||||
/// Validates the basic structure of the msgpack-rpc call and fills `res`
|
/// Validates the basic structure of the msgpack-rpc call and fills `res`
|
||||||
/// with the basic response structure.
|
/// with the basic response structure.
|
||||||
///
|
///
|
||||||
|
/// @param id The channel id
|
||||||
/// @param req The parsed request object
|
/// @param req The parsed request object
|
||||||
/// @param res A packer that contains the response
|
/// @param res A packer that contains the response
|
||||||
void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res);
|
void msgpack_rpc_call(uint64_t id, msgpack_object *req, msgpack_packer *res);
|
||||||
|
|
||||||
/// Dispatches to the actual API function after basic payload validation by
|
/// Dispatches to the actual API function after basic payload validation by
|
||||||
/// `msgpack_rpc_call`. It is responsible for validating/converting arguments
|
/// `msgpack_rpc_call`. It is responsible for validating/converting arguments
|
||||||
@ -21,9 +22,12 @@ void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res);
|
|||||||
/// The implementation is generated at compile time with metadata extracted
|
/// The implementation is generated at compile time with metadata extracted
|
||||||
/// from the api/*.h headers,
|
/// from the api/*.h headers,
|
||||||
///
|
///
|
||||||
|
/// @param id The channel id
|
||||||
/// @param req The parsed request object
|
/// @param req The parsed request object
|
||||||
/// @param res A packer that contains the response
|
/// @param res A packer that contains the response
|
||||||
void msgpack_rpc_dispatch(msgpack_object *req, msgpack_packer *res);
|
void msgpack_rpc_dispatch(uint64_t id,
|
||||||
|
msgpack_object *req,
|
||||||
|
msgpack_packer *res);
|
||||||
|
|
||||||
/// Finishes the msgpack-rpc call with an error message.
|
/// Finishes the msgpack-rpc call with an error message.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user