From de3a515123fa417ecce61efebe4bc117b010c657 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 16 Jun 2016 13:35:04 +0200 Subject: api: rename "msgpack_rpc/defs.h" to "api/private/dispatch.h" and use the header generator. --- src/nvim/api/private/dispatch.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/nvim/api/private/dispatch.h (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h new file mode 100644 index 0000000000..9047752026 --- /dev/null +++ b/src/nvim/api/private/dispatch.h @@ -0,0 +1,21 @@ +#ifndef NVIM_API_PRIVATE_DISPATCH_H +#define NVIM_API_PRIVATE_DISPATCH_H + +#include "nvim/api/private/defs.h" + +/// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores +/// functions of this type. +typedef struct { + Object (*fn)(uint64_t channel_id, + uint64_t request_id, + Array args, + Error *error); + bool async; // function is always safe to run immediately instead of being + // put in a request queue for handling when nvim waits for input. +} MsgpackRpcRequestHandler; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/private/dispatch.h.generated.h" +#endif + +#endif // NVIM_API_PRIVATE_DISPATCH_H -- cgit From 3bd3b3b76859b3eef80fa4969147efa881b60f40 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 18 Jun 2016 12:06:50 +0200 Subject: api: auto generate api function wrappers for viml --- src/nvim/api/private/dispatch.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index 9047752026..d91456c306 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -3,13 +3,15 @@ #include "nvim/api/private/defs.h" +typedef Object (*ApiDispatchWrapper)(uint64_t channel_id, + uint64_t request_id, + Array args, + Error *error); + /// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores /// functions of this type. typedef struct { - Object (*fn)(uint64_t channel_id, - uint64_t request_id, - Array args, - Error *error); + ApiDispatchWrapper fn; bool async; // function is always safe to run immediately instead of being // put in a request queue for handling when nvim waits for input. } MsgpackRpcRequestHandler; -- cgit From a2d25b7bf81728d913e7b317d33997c8b8268af2 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 19 Jun 2016 21:06:03 +0200 Subject: api: unify buffer numbers and window ids with handles also allow handle==0 meaning curbuf/curwin/curtab --- src/nvim/api/private/defs.h | 4 +++- src/nvim/api/private/handle.c | 16 ++++++---------- src/nvim/api/private/handle.h | 3 ++- src/nvim/api/private/helpers.c | 12 ++++++++++++ 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 5fb95a163f..3e0819ba3a 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -9,13 +9,15 @@ #define STRING_INIT {.data = NULL, .size = 0} #define OBJECT_INIT { .type = kObjectTypeNil } #define ERROR_INIT { .set = false } -#define REMOTE_TYPE(type) typedef uint64_t type +#define REMOTE_TYPE(type) typedef handle_T type #ifdef INCLUDE_GENERATED_DECLARATIONS # define ArrayOf(...) Array # define DictionaryOf(...) Dictionary #endif +typedef int handle_T; + // Basic types typedef enum { kErrorTypeException, diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c index 69df7294ad..acb0fb332a 100644 --- a/src/nvim/api/private/handle.c +++ b/src/nvim/api/private/handle.c @@ -5,30 +5,26 @@ #include "nvim/map.h" #include "nvim/api/private/handle.h" -#define HANDLE_INIT(name) name##_handles = pmap_new(uint64_t)() +#define HANDLE_INIT(name) name##_handles = pmap_new(handle_T)() #define HANDLE_IMPL(type, name) \ - static PMap(uint64_t) *name##_handles = NULL; \ + static PMap(handle_T) *name##_handles = NULL; /* NOLINT */ \ \ - type *handle_get_##name(uint64_t handle) \ + type *handle_get_##name(handle_T handle) \ { \ - return pmap_get(uint64_t)(name##_handles, handle); \ + return pmap_get(handle_T)(name##_handles, handle); \ } \ \ void handle_register_##name(type *name) \ { \ - assert(!name->handle); \ - name->handle = next_handle++; \ - pmap_put(uint64_t)(name##_handles, name->handle, name); \ + pmap_put(handle_T)(name##_handles, name->handle, name); \ } \ \ void handle_unregister_##name(type *name) \ { \ - pmap_del(uint64_t)(name##_handles, name->handle); \ + pmap_del(handle_T)(name##_handles, name->handle); \ } -static uint64_t next_handle = 1; - HANDLE_IMPL(buf_T, buffer) HANDLE_IMPL(win_T, window) HANDLE_IMPL(tabpage_T, tabpage) diff --git a/src/nvim/api/private/handle.h b/src/nvim/api/private/handle.h index 804e266dc3..30bbfbee1b 100644 --- a/src/nvim/api/private/handle.h +++ b/src/nvim/api/private/handle.h @@ -3,9 +3,10 @@ #include "nvim/vim.h" #include "nvim/buffer_defs.h" +#include "nvim/api/private/defs.h" #define HANDLE_DECLS(type, name) \ - type *handle_get_##name(uint64_t handle); \ + type *handle_get_##name(handle_T handle); \ void handle_register_##name(type *name); \ void handle_unregister_##name(type *name); diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index c88bf2127a..32cdb03130 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -507,6 +507,10 @@ Object vim_to_object(typval_T *obj) buf_T *find_buffer_by_handle(Buffer buffer, Error *err) { + if (buffer == 0) { + return curbuf; + } + buf_T *rv = handle_get_buffer(buffer); if (!rv) { @@ -518,6 +522,10 @@ buf_T *find_buffer_by_handle(Buffer buffer, Error *err) win_T * find_window_by_handle(Window window, Error *err) { + if (window == 0) { + return curwin; + } + win_T *rv = handle_get_window(window); if (!rv) { @@ -529,6 +537,10 @@ win_T * find_window_by_handle(Window window, Error *err) tabpage_T * find_tab_by_handle(Tabpage tabpage, Error *err) { + if (tabpage == 0) { + return curtab; + } + tabpage_T *rv = handle_get_tabpage(tabpage); if (!rv) { -- cgit From 87e054bb24cd4ba8cd06eb1a65f956c6bcce222d Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 18 Jun 2016 13:45:39 +0200 Subject: api: When calling get/set_lines from vimL, don't convert between "\n" and "\0". --- src/nvim/api/private/defs.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 3e0819ba3a..a6710193ff 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -33,6 +33,9 @@ typedef enum { /// Used as the message ID of notifications. #define NO_RESPONSE UINT64_MAX +/// Used as channel_id when the call is local +#define INVALID_CHANNEL UINT64_MAX + typedef struct { ErrorType type; char msg[1024]; -- cgit From 1c22cab2fd283db49bfdbeaea490747574a36049 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 28 Jun 2016 21:45:19 +0200 Subject: api: consistently use nvim_ prefix and update documentation --- src/nvim/api/private/helpers.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api/private') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 32cdb03130..7df2079d93 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -776,12 +776,15 @@ static void init_type_metadata(Dictionary *metadata) Dictionary buffer_metadata = ARRAY_DICT_INIT; PUT(buffer_metadata, "id", INTEGER_OBJ(kObjectTypeBuffer)); + PUT(buffer_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_buf_"))); Dictionary window_metadata = ARRAY_DICT_INIT; PUT(window_metadata, "id", INTEGER_OBJ(kObjectTypeWindow)); + PUT(window_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_win_"))); Dictionary tabpage_metadata = ARRAY_DICT_INIT; PUT(tabpage_metadata, "id", INTEGER_OBJ(kObjectTypeTabpage)); + PUT(tabpage_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_tabpage_"))); PUT(types, "Buffer", DICTIONARY_OBJ(buffer_metadata)); PUT(types, "Window", DICTIONARY_OBJ(window_metadata)); -- cgit