mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 14:28:18 +00:00

- Add error type information to `Error` - Rename `set_api_error` to `api_set_error` for consistency with other api_* functions/macros. - Refactor the api_set_error macro to accept formatted strings and error types - Improve error messages - Wrap error messages with gettext macro - Refactor msgpack-rpc serialization to transform Error instances into [type, message] arrays - Add error type information to API metadata - Normalize nvim->client and client->nvim error handling(change channel_send_call to accept an Error pointer instead of the `errored` boolean pointer) - Use macro to initialize Error structures
94 lines
1.6 KiB
C
94 lines
1.6 KiB
C
#ifndef NVIM_API_PRIVATE_DEFS_H
|
|
#define NVIM_API_PRIVATE_DEFS_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
|
|
#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
|
|
|
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
|
#define ArrayOf(...) Array
|
|
#define DictionaryOf(...) Dictionary
|
|
#endif
|
|
|
|
// Basic types
|
|
typedef enum {
|
|
kErrorTypeException,
|
|
kErrorTypeValidation
|
|
} ErrorType;
|
|
|
|
typedef struct {
|
|
ErrorType type;
|
|
char msg[1024];
|
|
bool set;
|
|
} Error;
|
|
|
|
typedef bool Boolean;
|
|
typedef int64_t Integer;
|
|
typedef double Float;
|
|
|
|
typedef struct {
|
|
char *data;
|
|
size_t size;
|
|
} String;
|
|
|
|
REMOTE_TYPE(Buffer);
|
|
REMOTE_TYPE(Window);
|
|
REMOTE_TYPE(Tabpage);
|
|
|
|
typedef struct object Object;
|
|
|
|
typedef struct {
|
|
Object *items;
|
|
size_t size, capacity;
|
|
} Array;
|
|
|
|
typedef struct key_value_pair KeyValuePair;
|
|
|
|
typedef struct {
|
|
KeyValuePair *items;
|
|
size_t size, capacity;
|
|
} Dictionary;
|
|
|
|
typedef enum {
|
|
kObjectTypeBuffer,
|
|
kObjectTypeWindow,
|
|
kObjectTypeTabpage,
|
|
kObjectTypeNil,
|
|
kObjectTypeBoolean,
|
|
kObjectTypeInteger,
|
|
kObjectTypeFloat,
|
|
kObjectTypeString,
|
|
kObjectTypeArray,
|
|
kObjectTypeDictionary,
|
|
} ObjectType;
|
|
|
|
struct object {
|
|
ObjectType type;
|
|
union {
|
|
Buffer buffer;
|
|
Window window;
|
|
Tabpage tabpage;
|
|
Boolean boolean;
|
|
Integer integer;
|
|
Float floating;
|
|
String string;
|
|
Array array;
|
|
Dictionary dictionary;
|
|
} data;
|
|
};
|
|
|
|
struct key_value_pair {
|
|
String key;
|
|
Object value;
|
|
};
|
|
|
|
|
|
#endif // NVIM_API_PRIVATE_DEFS_H
|
|
|