mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 03:46:31 +00:00
channel/msgpack_rpc: Refactor API dispatching
This is how API dispatching worked before this commit: - The generated `msgpack_rpc_dispatch` function receives a the `msgpack_packer` argument. - The response is incrementally built while validating/calling the API. - Return values/errors are also packed into the `msgpack_packer` while the final response is being calculated. Now the `msgpack_packer` argument is no longer provided, and the `msgpack_rpc_dispatch` function returns `Object`/`Error` values to `msgpack_rpc_call`, which will use those values to build the response in a single pass. This was done because the new `channel_send_call` function created the possibility of having recursive API invocations, and this wasn't possible when sharing a single `msgpack_sbuffer` across call frames(it was shared implicitly through the `msgpack_packer` instance). Since we only start to build the response when the necessary information has been computed, it's now safe to share a single `msgpack_sbuffer` instance across all channels and API invocations. Some other changes also had to be performed: - Handling of the metadata discover was moved to `msgpack_rpc_call` - Expose more types as subtypes of `Object`, this was required to forward the return value from `msgpack_rpc_dispatch` to `msgpack_rpc_call` - Added more helper macros for casting API types to `Object` any
This commit is contained in:
@@ -65,8 +65,16 @@ typedef enum {
|
||||
kObjectTypeInteger,
|
||||
kObjectTypeFloat,
|
||||
kObjectTypeString,
|
||||
kObjectTypeBuffer,
|
||||
kObjectTypeWindow,
|
||||
kObjectTypeTabpage,
|
||||
kObjectTypeArray,
|
||||
kObjectTypeDictionary
|
||||
kObjectTypeDictionary,
|
||||
kObjectTypePosition,
|
||||
kObjectTypeStringArray,
|
||||
kObjectTypeBufferArray,
|
||||
kObjectTypeWindowArray,
|
||||
kObjectTypeTabpageArray,
|
||||
} ObjectType;
|
||||
|
||||
struct object {
|
||||
@@ -76,8 +84,16 @@ struct object {
|
||||
Integer integer;
|
||||
Float floating;
|
||||
String string;
|
||||
Buffer buffer;
|
||||
Window window;
|
||||
Tabpage tabpage;
|
||||
Array array;
|
||||
Dictionary dictionary;
|
||||
Position position;
|
||||
StringArray stringarray;
|
||||
BufferArray bufferarray;
|
||||
WindowArray windowarray;
|
||||
TabpageArray tabpagearray;
|
||||
} data;
|
||||
};
|
||||
|
||||
|
@@ -426,6 +426,8 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
||||
}
|
||||
tv->vval.v_dict->dv_refcount++;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -14,7 +14,9 @@
|
||||
err->set = true; \
|
||||
} while (0)
|
||||
|
||||
#define BOOL_OBJ(b) ((Object) { \
|
||||
#define OBJECT_OBJ(o) o
|
||||
|
||||
#define BOOLEAN_OBJ(b) ((Object) { \
|
||||
.type = kObjectTypeBoolean, \
|
||||
.data.boolean = b \
|
||||
})
|
||||
@@ -26,26 +28,59 @@
|
||||
|
||||
#define STRING_OBJ(s) ((Object) { \
|
||||
.type = kObjectTypeString, \
|
||||
.data.string = cstr_to_string(s) \
|
||||
.data.string = s \
|
||||
})
|
||||
|
||||
#define STRINGL_OBJ(d, s) ((Object) { \
|
||||
.type = kObjectTypeString, \
|
||||
.data.string = (String) { \
|
||||
.size = s, \
|
||||
.data = xmemdup(d, s) \
|
||||
}})
|
||||
#define BUFFER_OBJ(s) ((Object) { \
|
||||
.type = kObjectTypeBuffer, \
|
||||
.data.buffer = s \
|
||||
})
|
||||
|
||||
#define WINDOW_OBJ(s) ((Object) { \
|
||||
.type = kObjectTypeWindow, \
|
||||
.data.window = s \
|
||||
})
|
||||
|
||||
#define TABPAGE_OBJ(s) ((Object) { \
|
||||
.type = kObjectTypeTabpage, \
|
||||
.data.tabpage = s \
|
||||
})
|
||||
|
||||
#define ARRAY_OBJ(a) ((Object) { \
|
||||
.type = kObjectTypeArray, \
|
||||
.data.array = a \
|
||||
})
|
||||
|
||||
#define STRINGARRAY_OBJ(a) ((Object) { \
|
||||
.type = kObjectTypeStringArray, \
|
||||
.data.stringarray = a \
|
||||
})
|
||||
|
||||
#define BUFFERARRAY_OBJ(a) ((Object) { \
|
||||
.type = kObjectTypeBufferArray, \
|
||||
.data.bufferarray = a \
|
||||
})
|
||||
|
||||
#define WINDOWARRAY_OBJ(a) ((Object) { \
|
||||
.type = kObjectTypeWindowArray, \
|
||||
.data.windowarray = a \
|
||||
})
|
||||
|
||||
#define TABPAGEARRAY_OBJ(a) ((Object) { \
|
||||
.type = kObjectTypeTabpageArray, \
|
||||
.data.tabpagearray = a \
|
||||
})
|
||||
|
||||
#define DICTIONARY_OBJ(d) ((Object) { \
|
||||
.type = kObjectTypeDictionary, \
|
||||
.data.dictionary = d \
|
||||
})
|
||||
|
||||
#define POSITION_OBJ(p) ((Object) { \
|
||||
.type = kObjectTypePosition, \
|
||||
.data.position = p \
|
||||
})
|
||||
|
||||
#define NIL ((Object) {.type = kObjectTypeNil})
|
||||
|
||||
#define PUT(dict, k, v) \
|
||||
|
Reference in New Issue
Block a user