mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
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.
This commit is contained in:
@@ -38,9 +38,28 @@ assert(#arg >= 1)
|
|||||||
-- api metadata
|
-- api metadata
|
||||||
api = {
|
api = {
|
||||||
functions = {},
|
functions = {},
|
||||||
-- Helpers for object-oriented languages
|
types = {}
|
||||||
classes = {'Buffer', 'Window', 'Tabpage'}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Extract type codes from api/private/defs.h. The codes are values between
|
||||||
|
-- comment markers in the ObjectType enum
|
||||||
|
local typedefs_header = arg[1]
|
||||||
|
local input = io.open(typedefs_header, 'rb')
|
||||||
|
local reading_types = false
|
||||||
|
while true do
|
||||||
|
local line = input:read('*l'):gsub("^%s*(.-)%s*$", "%1")
|
||||||
|
if reading_types then
|
||||||
|
if line == '// end custom types' then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local type_name = line:gsub("^kObjectType(.-),$", "%1")
|
||||||
|
api.types[#api.types + 1] = type_name
|
||||||
|
else
|
||||||
|
reading_types = line == '// start custom types'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
input:close()
|
||||||
|
|
||||||
-- names of all headers relative to the source root(for inclusion in the
|
-- names of all headers relative to the source root(for inclusion in the
|
||||||
-- generated file)
|
-- generated file)
|
||||||
headers = {}
|
headers = {}
|
||||||
@@ -48,7 +67,7 @@ headers = {}
|
|||||||
outputf = arg[#arg]
|
outputf = arg[#arg]
|
||||||
|
|
||||||
-- read each input file, parse and append to the api metadata
|
-- read each input file, parse and append to the api metadata
|
||||||
for i = 1, #arg - 1 do
|
for i = 2, #arg - 1 do
|
||||||
local full_path = arg[i]
|
local full_path = arg[i]
|
||||||
local parts = {}
|
local parts = {}
|
||||||
for part in string.gmatch(full_path, '[^/]+') do
|
for part in string.gmatch(full_path, '[^/]+') do
|
||||||
|
@@ -3,6 +3,7 @@ include(CheckLibraryExists)
|
|||||||
set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto)
|
set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto)
|
||||||
set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua)
|
set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua)
|
||||||
file(GLOB API_HEADERS api/*.h)
|
file(GLOB API_HEADERS api/*.h)
|
||||||
|
file(GLOB API_DEFS api/private/defs.h)
|
||||||
set(MSGPACK_RPC_HEADER ${PROJECT_SOURCE_DIR}/src/nvim/os/msgpack_rpc.h)
|
set(MSGPACK_RPC_HEADER ${PROJECT_SOURCE_DIR}/src/nvim/os/msgpack_rpc.h)
|
||||||
set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c)
|
set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c)
|
||||||
set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
|
set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
|
||||||
@@ -123,9 +124,10 @@ foreach(sfile ${NEOVIM_SOURCES}
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
add_custom_command(OUTPUT ${MSGPACK_DISPATCH}
|
add_custom_command(OUTPUT ${MSGPACK_DISPATCH}
|
||||||
COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_HEADERS} ${MSGPACK_DISPATCH}
|
COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_DEFS} ${API_HEADERS} ${MSGPACK_DISPATCH}
|
||||||
DEPENDS
|
DEPENDS
|
||||||
${API_HEADERS}
|
${API_HEADERS}
|
||||||
|
${API_DEFS}
|
||||||
${MSGPACK_RPC_HEADER}
|
${MSGPACK_RPC_HEADER}
|
||||||
${DISPATCH_GENERATOR}
|
${DISPATCH_GENERATOR}
|
||||||
)
|
)
|
||||||
|
@@ -49,32 +49,36 @@ typedef struct {
|
|||||||
} Dictionary;
|
} Dictionary;
|
||||||
|
|
||||||
typedef enum {
|
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,
|
kObjectTypeNil,
|
||||||
kObjectTypeBoolean,
|
kObjectTypeBoolean,
|
||||||
kObjectTypeInteger,
|
kObjectTypeInteger,
|
||||||
kObjectTypeFloat,
|
kObjectTypeFloat,
|
||||||
kObjectTypeString,
|
kObjectTypeString,
|
||||||
kObjectTypeBuffer,
|
|
||||||
kObjectTypeWindow,
|
|
||||||
kObjectTypeTabpage,
|
|
||||||
kObjectTypeArray,
|
kObjectTypeArray,
|
||||||
kObjectTypeDictionary,
|
kObjectTypeDictionary,
|
||||||
kObjectTypePosition,
|
|
||||||
} ObjectType;
|
} ObjectType;
|
||||||
|
|
||||||
struct object {
|
struct object {
|
||||||
ObjectType type;
|
ObjectType type;
|
||||||
union {
|
union {
|
||||||
|
Position position;
|
||||||
|
Buffer buffer;
|
||||||
|
Window window;
|
||||||
|
Tabpage tabpage;
|
||||||
Boolean boolean;
|
Boolean boolean;
|
||||||
Integer integer;
|
Integer integer;
|
||||||
Float floating;
|
Float floating;
|
||||||
String string;
|
String string;
|
||||||
Buffer buffer;
|
|
||||||
Window window;
|
|
||||||
Tabpage tabpage;
|
|
||||||
Array array;
|
Array array;
|
||||||
Dictionary dictionary;
|
Dictionary dictionary;
|
||||||
Position position;
|
|
||||||
} data;
|
} data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user