From d5a60d17fbca33ca96124288e69937a276d3abda Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sun, 7 Sep 2014 18:48:10 -0300 Subject: api/msgpack-rpc: Remove specialized array types Specialized array types(BufferArray, WindowArray, etc) were added to the API for two main reasons: - msgpack used to lack a way of serializing appliaction-specific types and there was no obvious way of making an API function accept/return arrays of custom objects such as buffers(which are represented as integers, so clients didn't have a way to distinguish from normal numbers) - Let clients in statically-typed languages that support generics have a better typed API With msgpack 2.0 EXT type the first item is no longer a factor and this commit starts by removing the specialized array types. The second item will be addressed in the future by making the API metadata return extra useful information for statically-typed languages. --- src/nvim/api/private/defs.h | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src/nvim/api/private/defs.h') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index b049412014..071563a628 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -11,12 +11,6 @@ #define POSITION_INIT { .row = 0, .col = 0 } #define REMOTE_TYPE(type) typedef uint64_t type -#define TYPED_ARRAY_OF(type) \ - typedef struct { \ - type *items; \ - size_t size; \ - } type##Array - // Basic types typedef struct { char msg[256]; @@ -38,11 +32,6 @@ REMOTE_TYPE(Tabpage); typedef struct object Object; -TYPED_ARRAY_OF(Buffer); -TYPED_ARRAY_OF(Window); -TYPED_ARRAY_OF(Tabpage); -TYPED_ARRAY_OF(String); - typedef struct { Integer row, col; } Position; @@ -71,10 +60,6 @@ typedef enum { kObjectTypeArray, kObjectTypeDictionary, kObjectTypePosition, - kObjectTypeStringArray, - kObjectTypeBufferArray, - kObjectTypeWindowArray, - kObjectTypeTabpageArray, } ObjectType; struct object { @@ -90,10 +75,6 @@ struct object { Array array; Dictionary dictionary; Position position; - StringArray stringarray; - BufferArray bufferarray; - WindowArray windowarray; - TabpageArray tabpagearray; } data; }; -- cgit From 2f566c83d9eee4a8097c9a18eb58dcef6adf894e Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sun, 7 Sep 2014 20:40:07 -0300 Subject: api/msgpack-rpc: Parse type information from api/private/defs.h Enhance msgpack-gen.lua to extract custom api type codes from the ObjectType enum in api/private/defs.h. The type information is made available from the api metadata and clients can use to correctly serialize/deserialize these types using msgpack EXT type. --- src/nvim/api/private/defs.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/nvim/api/private/defs.h') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 071563a628..689594f231 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -49,32 +49,36 @@ typedef struct { } Dictionary; typedef enum { +// The following comments are markers that msgpack-gen.lua uses to extract +// types, don't remove! +// start custom types + kObjectTypePosition, + kObjectTypeBuffer, + kObjectTypeWindow, + kObjectTypeTabpage, +// end custom types kObjectTypeNil, kObjectTypeBoolean, kObjectTypeInteger, kObjectTypeFloat, kObjectTypeString, - kObjectTypeBuffer, - kObjectTypeWindow, - kObjectTypeTabpage, kObjectTypeArray, kObjectTypeDictionary, - kObjectTypePosition, } ObjectType; struct object { ObjectType type; union { + Position position; + Buffer buffer; + Window window; + Tabpage tabpage; Boolean boolean; Integer integer; Float floating; String string; - Buffer buffer; - Window window; - Tabpage tabpage; Array array; Dictionary dictionary; - Position position; } data; }; -- cgit From 2792a0e33c0845fdd5b1b752d99ee573f6534256 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Tue, 9 Sep 2014 08:59:48 -0300 Subject: api/msgpack-rpc: Remove Position type, using arrays instead. --- src/nvim/api/private/defs.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/nvim/api/private/defs.h') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 689594f231..11800ed786 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -8,7 +8,6 @@ #define ARRAY_DICT_INIT {.size = 0, .items = NULL} #define STRING_INIT {.data = NULL, .size = 0} #define OBJECT_INIT { .type = kObjectTypeNil } -#define POSITION_INIT { .row = 0, .col = 0 } #define REMOTE_TYPE(type) typedef uint64_t type // Basic types @@ -32,10 +31,6 @@ REMOTE_TYPE(Tabpage); typedef struct object Object; -typedef struct { - Integer row, col; -} Position; - typedef struct { Object *items; size_t size, capacity; @@ -52,7 +47,6 @@ typedef enum { // The following comments are markers that msgpack-gen.lua uses to extract // types, don't remove! // start custom types - kObjectTypePosition, kObjectTypeBuffer, kObjectTypeWindow, kObjectTypeTabpage, @@ -69,7 +63,6 @@ typedef enum { struct object { ObjectType type; union { - Position position; Buffer buffer; Window window; Tabpage tabpage; -- cgit From d29b62daabd88e3c7ee9a979f4feae5612e3fbaf Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 11 Sep 2014 10:34:51 -0300 Subject: api: initialize capacity in the array_dict_macro --- src/nvim/api/private/defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/private/defs.h') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 11800ed786..bae1819172 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -5,7 +5,7 @@ #include #include -#define ARRAY_DICT_INIT {.size = 0, .items = NULL} +#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL} #define STRING_INIT {.data = NULL, .size = 0} #define OBJECT_INIT { .type = kObjectTypeNil } #define REMOTE_TYPE(type) typedef uint64_t type -- cgit From cd2e46c0785d40b9ea15f6d722a3fad54c007b9b Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 11 Sep 2014 21:56:52 -0300 Subject: api/msgpack-rpc: Refactor metadata object construction Instead of building all metadata from msgpack-gen.lua, we now merge the generated part with manual information(such as types and features). The metadata is accessible through the api method `vim_get_api_info`. This was done to simplify the generator while also increasing flexibility(by being able to add more metadata) --- src/nvim/api/private/defs.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/nvim/api/private/defs.h') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index bae1819172..cf559a372e 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -44,13 +44,9 @@ typedef struct { } Dictionary; typedef enum { -// The following comments are markers that msgpack-gen.lua uses to extract -// types, don't remove! -// start custom types kObjectTypeBuffer, kObjectTypeWindow, kObjectTypeTabpage, -// end custom types kObjectTypeNil, kObjectTypeBoolean, kObjectTypeInteger, -- cgit From 545acf2024ea2653ae6937d570a37aa0340caa5e Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 12 Sep 2014 11:24:01 -0300 Subject: api metadata: Allow typed container information in api functions Adapt gendeclarations.lua/msgpack-gen.lua to allow the `ArrayOf(...)` and `DictionaryOf(...)` types in function headers. These are simple macros that expand to Array and Dictionary respectively, but the information is kept in the metadata object, which is useful for building clients in statically typed languages. --- src/nvim/api/private/defs.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/api/private/defs.h') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index cf559a372e..2dd229ec5f 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -10,6 +10,11 @@ #define OBJECT_INIT { .type = kObjectTypeNil } #define REMOTE_TYPE(type) typedef uint64_t type +#ifdef INCLUDE_GENERATED_DECLARATIONS + #define ArrayOf(...) Array + #define DictionaryOf(...) Dictionary +#endif + // Basic types typedef struct { char msg[256]; -- cgit