aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authormicha <michoffmann.potsdam@gmail.com>2018-06-27 17:08:55 +0200
committermicha <michoffmann.potsdam@gmail.com>2018-07-14 11:47:18 +0200
commited02278e42b822a339a12475d81c377271e528f8 (patch)
tree7eb231c60492fef38288bd46fb9d94131e5ab097 /src/nvim/api
parent4874214139ab86f7033d5e6c602f7515ed813443 (diff)
downloadrneovim-ed02278e42b822a339a12475d81c377271e528f8.tar.gz
rneovim-ed02278e42b822a339a12475d81c377271e528f8.tar.bz2
rneovim-ed02278e42b822a339a12475d81c377271e528f8.zip
channel.c: refactor spaghetti code
channel.c: WIP remove redundant method check and added FUNC_ATTR_NONNULL_ALL macro channel.c channel_defs.h helpers.c: added Error field to RequestEvent, added no_op handler func channel.c: use const char* instead of string and cleanup channel.c; channel_defs.h; helpers.c: removed error from event again; send errors directly to the channel without using handlers and events channel.c: fixed memory leak and lint errors api/private/dispatch.c; api/vim.c; msgpack_rpc/channel.c msgpack_rpc/helpers.c added Error* field to msgpack_get_handler_for; further refactored channel.c channel.c:323 changed order of evaluation in if statement channel.c: removed superflous whitespace dispatch.c: review comment
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/private/dispatch.c9
-rw-r--r--src/nvim/api/vim.c11
2 files changed, 12 insertions, 8 deletions
diff --git a/src/nvim/api/private/dispatch.c b/src/nvim/api/private/dispatch.c
index 5207a57b88..2e59d3faa9 100644
--- a/src/nvim/api/private/dispatch.c
+++ b/src/nvim/api/private/dispatch.c
@@ -32,16 +32,19 @@ static void msgpack_rpc_add_method_handler(String method,
/// @param name API method name
/// @param name_len name size (includes terminating NUL)
MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name,
- size_t name_len)
+ size_t name_len,
+ Error *error)
{
String m = { .data = (char *)name, .size = name_len };
MsgpackRpcRequestHandler rv =
map_get(String, MsgpackRpcRequestHandler)(methods, m);
if (!rv.fn) {
- rv.fn = msgpack_rpc_handle_missing_method;
+ String method_name = m.size > 0 ?
+ m : cstr_as_string("<empty>");
+ api_set_error(error, kErrorTypeException, "Invalid method: %s",
+ method_name);
}
-
return rv;
}
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 002d9da781..03567ddfd8 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1162,11 +1162,12 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err)
}
Array args = call.items[1].data.array;
- MsgpackRpcRequestHandler handler = msgpack_rpc_get_handler_for(name.data,
- name.size);
- if (handler.fn == msgpack_rpc_handle_missing_method) {
- api_set_error(&nested_error, kErrorTypeException, "Invalid method: %s",
- name.size > 0 ? name.data : "<empty>");
+ MsgpackRpcRequestHandler handler =
+ msgpack_rpc_get_handler_for(name.data,
+ name.size,
+ &nested_error);
+
+ if (ERROR_SET(&nested_error)) {
break;
}
Object result = handler.fn(channel_id, args, &nested_error);