1#ifndef NVIM_API_PRIVATE_DEFS_H
2#define NVIM_API_PRIVATE_DEFS_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include <string.h>
7
8#include "nvim/func_attr.h"
9#include "nvim/types.h"
10
11#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
12#define STRING_INIT {.data = NULL, .size = 0}
13#define OBJECT_INIT { .type = kObjectTypeNil }
14#define ERROR_INIT { .type = kErrorTypeNone, .msg = NULL }
15#define REMOTE_TYPE(type) typedef handle_T type
16
17#define ERROR_SET(e) ((e)->type != kErrorTypeNone)
18
19#ifdef INCLUDE_GENERATED_DECLARATIONS
20# define ArrayOf(...) Array
21# define DictionaryOf(...) Dictionary
22#endif
23
24// Basic types
25typedef enum {
26 kErrorTypeNone = -1,
27 kErrorTypeException,
28 kErrorTypeValidation
29} ErrorType;
30
31typedef enum {
32 kMessageTypeUnknown = -1,
33 // Per msgpack-rpc spec.
34 kMessageTypeRequest = 0,
35 kMessageTypeResponse = 1,
36 kMessageTypeNotification = 2,
37} MessageType;
38
39/// Mask for all internal calls
40#define INTERNAL_CALL_MASK (((uint64_t)1) << (sizeof(uint64_t) * 8 - 1))
41
42/// Internal call from VimL code
43#define VIML_INTERNAL_CALL INTERNAL_CALL_MASK
44
45/// Internal call from lua code
46#define LUA_INTERNAL_CALL (VIML_INTERNAL_CALL + 1)
47
48static inline bool is_internal_call(const uint64_t channel_id)
49 REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
50
51/// Check whether call is internal
52///
53/// @param[in] channel_id Channel id.
54///
55/// @return true if channel_id refers to internal channel.
56static inline bool is_internal_call(const uint64_t channel_id)
57{
58 return !!(channel_id & INTERNAL_CALL_MASK);
59}
60
61typedef struct {
62 ErrorType type;
63 char *msg;
64} Error;
65
66typedef bool Boolean;
67typedef int64_t Integer;
68typedef double Float;
69
70/// Maximum value of an Integer
71#define API_INTEGER_MAX INT64_MAX
72
73/// Minimum value of an Integer
74#define API_INTEGER_MIN INT64_MIN
75
76typedef struct {
77 char *data;
78 size_t size;
79} String;
80
81REMOTE_TYPE(Buffer);
82REMOTE_TYPE(Window);
83REMOTE_TYPE(Tabpage);
84
85typedef struct object Object;
86
87typedef struct {
88 Object *items;
89 size_t size, capacity;
90} Array;
91
92typedef struct key_value_pair KeyValuePair;
93
94typedef struct {
95 KeyValuePair *items;
96 size_t size, capacity;
97} Dictionary;
98
99typedef enum {
100 kObjectTypeNil = 0,
101 kObjectTypeBoolean,
102 kObjectTypeInteger,
103 kObjectTypeFloat,
104 kObjectTypeString,
105 kObjectTypeArray,
106 kObjectTypeDictionary,
107 kObjectTypeLuaRef,
108 // EXT types, cannot be split or reordered, see #EXT_OBJECT_TYPE_SHIFT
109 kObjectTypeBuffer,
110 kObjectTypeWindow,
111 kObjectTypeTabpage,
112} ObjectType;
113
114struct object {
115 ObjectType type;
116 union {
117 Boolean boolean;
118 Integer integer;
119 Float floating;
120 String string;
121 Array array;
122 Dictionary dictionary;
123 LuaRef luaref;
124 } data;
125};
126
127struct key_value_pair {
128 String key;
129 Object value;
130};
131
132
133#endif // NVIM_API_PRIVATE_DEFS_H
134