mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
api: add metadata for ui events
This commit is contained in:
parent
7d6af9985c
commit
e82cb5de4a
@ -48,6 +48,7 @@ version.api_compatible API is backwards-compatible with this level
|
||||
version.api_prerelease Declares the current API level as unstable >
|
||||
(version.api_prerelease && fn.since == version.api_level)
|
||||
functions API function signatures
|
||||
ui_events UI event signatures |rpc-remote-ui|
|
||||
{fn}.since API level where function {fn} was introduced
|
||||
{fn}.deprecated_since API level where function {fn} was deprecated
|
||||
types Custom handle types defined by Nvim
|
||||
|
@ -26,6 +26,7 @@ set(GENERATED_UI_EVENTS ${GENERATED_DIR}/ui_events.generated.h)
|
||||
set(GENERATED_UI_EVENTS_CALL ${GENERATED_DIR}/ui_events_call.generated.h)
|
||||
set(GENERATED_UI_EVENTS_REMOTE ${GENERATED_DIR}/ui_events_remote.generated.h)
|
||||
set(GENERATED_UI_EVENTS_BRIDGE ${GENERATED_DIR}/ui_events_bridge.generated.h)
|
||||
set(GENERATED_UI_EVENTS_METADATA ${GENERATED_DIR}/api/private/ui_events_metadata.generated.h)
|
||||
set(GENERATED_EX_CMDS_ENUM ${GENERATED_INCLUDES_DIR}/ex_cmds_enum.generated.h)
|
||||
set(GENERATED_EX_CMDS_DEFS ${GENERATED_DIR}/ex_cmds_defs.generated.h)
|
||||
set(GENERATED_FUNCS ${GENERATED_DIR}/funcs.generated.h)
|
||||
@ -269,12 +270,14 @@ add_custom_command(
|
||||
${GENERATED_UI_EVENTS_CALL}
|
||||
${GENERATED_UI_EVENTS_REMOTE}
|
||||
${GENERATED_UI_EVENTS_BRIDGE}
|
||||
${GENERATED_UI_EVENTS_METADATA}
|
||||
COMMAND ${LUA_PRG} ${API_UI_EVENTS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/api/ui_events.in.h
|
||||
${GENERATED_UI_EVENTS}
|
||||
${GENERATED_UI_EVENTS_CALL}
|
||||
${GENERATED_UI_EVENTS_REMOTE}
|
||||
${GENERATED_UI_EVENTS_BRIDGE}
|
||||
${GENERATED_UI_EVENTS_METADATA}
|
||||
DEPENDS
|
||||
${API_UI_EVENTS_GENERATOR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/api/ui_events.in.h
|
||||
|
@ -33,6 +33,7 @@ typedef struct {
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "api/private/helpers.c.generated.h"
|
||||
# include "api/private/funcs_metadata.generated.h"
|
||||
# include "api/private/ui_events_metadata.generated.h"
|
||||
#endif
|
||||
|
||||
/// Start block that may cause vimscript exceptions
|
||||
@ -820,6 +821,7 @@ Dictionary api_metadata(void)
|
||||
if (!metadata.size) {
|
||||
PUT(metadata, "version", DICTIONARY_OBJ(version_dict()));
|
||||
init_function_metadata(&metadata);
|
||||
init_ui_event_metadata(&metadata);
|
||||
init_error_type_metadata(&metadata);
|
||||
init_type_metadata(&metadata);
|
||||
}
|
||||
@ -843,6 +845,22 @@ static void init_function_metadata(Dictionary *metadata)
|
||||
PUT(*metadata, "functions", functions);
|
||||
}
|
||||
|
||||
static void init_ui_event_metadata(Dictionary *metadata)
|
||||
{
|
||||
msgpack_unpacked unpacked;
|
||||
msgpack_unpacked_init(&unpacked);
|
||||
if (msgpack_unpack_next(&unpacked,
|
||||
(const char *)ui_events_metadata,
|
||||
sizeof(ui_events_metadata),
|
||||
NULL) != MSGPACK_UNPACK_SUCCESS) {
|
||||
abort();
|
||||
}
|
||||
Object ui_events;
|
||||
msgpack_rpc_to_object(&unpacked.data, &ui_events);
|
||||
msgpack_unpacked_destroy(&unpacked);
|
||||
PUT(*metadata, "ui_events", ui_events);
|
||||
}
|
||||
|
||||
static void init_error_type_metadata(Dictionary *metadata)
|
||||
{
|
||||
Dictionary types = ARRAY_DICT_INIT;
|
||||
|
@ -3,41 +3,69 @@
|
||||
|
||||
// This file is not compiled, just parsed for definitons
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
#error "don't include this file, include nvim/ui.h"
|
||||
# error "don't include this file, include nvim/ui.h"
|
||||
#endif
|
||||
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/func_attr.h"
|
||||
#include "nvim/ui.h"
|
||||
|
||||
void resize(Integer rows, Integer columns);
|
||||
void clear(void);
|
||||
void eol_clear(void);
|
||||
void cursor_goto(Integer row, Integer col);
|
||||
void mode_info_set(Boolean enabled, Array cursor_styles);
|
||||
void update_menu(void);
|
||||
void busy_start(void);
|
||||
void busy_stop(void);
|
||||
void mouse_on(void);
|
||||
void mouse_off(void);
|
||||
void mode_change(String mode, Integer mode_idx);
|
||||
void set_scroll_region(Integer top, Integer bot, Integer left, Integer right);
|
||||
void scroll(Integer count);
|
||||
void highlight_set(HlAttrs attrs) REMOTE_IMPL BRIDGE_IMPL;
|
||||
void put(String str);
|
||||
void bell(void);
|
||||
void visual_bell(void);
|
||||
void flush(void) REMOTE_IMPL;
|
||||
void update_fg(Integer fg);
|
||||
void update_bg(Integer bg);
|
||||
void update_sp(Integer sp);
|
||||
void suspend(void) BRIDGE_IMPL;
|
||||
void set_title(String title);
|
||||
void set_icon(String icon);
|
||||
void resize(Integer rows, Integer columns)
|
||||
FUNC_API_SINCE(3);
|
||||
void clear(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void eol_clear(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void cursor_goto(Integer row, Integer col)
|
||||
FUNC_API_SINCE(3);
|
||||
void mode_info_set(Boolean enabled, Array cursor_styles)
|
||||
FUNC_API_SINCE(3);
|
||||
void update_menu(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void busy_start(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void busy_stop(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void mouse_on(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void mouse_off(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void mode_change(String mode, Integer mode_idx)
|
||||
FUNC_API_SINCE(3);
|
||||
void set_scroll_region(Integer top, Integer bot, Integer left, Integer right)
|
||||
FUNC_API_SINCE(3);
|
||||
void scroll(Integer count)
|
||||
FUNC_API_SINCE(3);
|
||||
void highlight_set(HlAttrs attrs)
|
||||
FUNC_API_SINCE(3) REMOTE_IMPL BRIDGE_IMPL;
|
||||
void put(String str)
|
||||
FUNC_API_SINCE(3);
|
||||
void bell(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void visual_bell(void)
|
||||
FUNC_API_SINCE(3);
|
||||
void flush(void)
|
||||
FUNC_API_SINCE(3) REMOTE_IMPL;
|
||||
void update_fg(Integer fg)
|
||||
FUNC_API_SINCE(3);
|
||||
void update_bg(Integer bg)
|
||||
FUNC_API_SINCE(3);
|
||||
void update_sp(Integer sp)
|
||||
FUNC_API_SINCE(3);
|
||||
void suspend(void)
|
||||
FUNC_API_SINCE(3) BRIDGE_IMPL;
|
||||
void set_title(String title)
|
||||
FUNC_API_SINCE(3);
|
||||
void set_icon(String icon)
|
||||
FUNC_API_SINCE(3);
|
||||
|
||||
void popupmenu_show(Array items, Integer selected, Integer row, Integer col) REMOTE_ONLY;
|
||||
void popupmenu_hide(void) REMOTE_ONLY;
|
||||
void popupmenu_select(Integer selected) REMOTE_ONLY;
|
||||
void tabline_update(Tabpage current, Array tabs) REMOTE_ONLY;
|
||||
void popupmenu_show(Array items, Integer selected, Integer row, Integer col)
|
||||
FUNC_API_SINCE(3) REMOTE_ONLY;
|
||||
void popupmenu_hide(void)
|
||||
FUNC_API_SINCE(3) REMOTE_ONLY;
|
||||
void popupmenu_select(Integer selected)
|
||||
FUNC_API_SINCE(3) REMOTE_ONLY;
|
||||
void tabline_update(Tabpage current, Array tabs)
|
||||
FUNC_API_SINCE(3) REMOTE_ONLY;
|
||||
|
||||
#endif // NVIM_API_UI_EVENTS_IN_H
|
||||
|
@ -3,12 +3,13 @@ mpack = require('mpack')
|
||||
local nvimdir = arg[1]
|
||||
package.path = nvimdir .. '/?.lua;' .. package.path
|
||||
|
||||
assert(#arg == 6)
|
||||
assert(#arg == 7)
|
||||
input = io.open(arg[2], 'rb')
|
||||
proto_output = io.open(arg[3], 'wb')
|
||||
call_output = io.open(arg[4], 'wb')
|
||||
remote_output = io.open(arg[5], 'wb')
|
||||
bridge_output = io.open(arg[6], 'wb')
|
||||
metadata_output = io.open(arg[7], 'wb')
|
||||
|
||||
c_grammar = require('generators.c_grammar')
|
||||
local events = c_grammar.grammar:match(input:read('*all'))
|
||||
@ -53,6 +54,12 @@ for i = 1, #events do
|
||||
ev = events[i]
|
||||
assert(ev.return_type == 'void')
|
||||
|
||||
if ev.since == nil then
|
||||
print("Ui event "..ev.name.." lacks since field.\n")
|
||||
os.exit(1)
|
||||
end
|
||||
ev.since = tonumber(ev.since)
|
||||
|
||||
if not ev.remote_only then
|
||||
proto_output:write(' void (*'..ev.name..')')
|
||||
write_signature(proto_output, ev, 'UI *ui')
|
||||
@ -134,3 +141,20 @@ end
|
||||
proto_output:close()
|
||||
call_output:close()
|
||||
remote_output:close()
|
||||
|
||||
-- don't expose internal attributes like "impl_name" in public metadata
|
||||
exported_attributes = {'name', 'parameters',
|
||||
'since', 'deprecated_since'}
|
||||
exported_events = {}
|
||||
for _,ev in ipairs(events) do
|
||||
local f_exported = {}
|
||||
for _,attr in ipairs(exported_attributes) do
|
||||
f_exported[attr] = ev[attr]
|
||||
end
|
||||
exported_events[#exported_events+1] = f_exported
|
||||
end
|
||||
|
||||
packed = mpack.pack(exported_events)
|
||||
dump_bin_array = require("generators.dump_bin_array")
|
||||
dump_bin_array(metadata_output, 'ui_events_metadata', packed)
|
||||
metadata_output:close()
|
||||
|
@ -106,7 +106,7 @@ describe('api functions', function()
|
||||
|
||||
it('have metadata accessible with api_info()', function()
|
||||
local api_keys = eval("sort(keys(api_info()))")
|
||||
eq({'error_types', 'functions', 'types', 'version'}, api_keys)
|
||||
eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_keys)
|
||||
end)
|
||||
|
||||
it('are highlighted by vim.vim syntax file', function()
|
||||
|
@ -461,7 +461,7 @@ describe('msgpackparse() function', function()
|
||||
eval(cmd)
|
||||
eval(cmd) -- do it again (try to force segfault)
|
||||
local api_info = eval(cmd) -- do it again
|
||||
eq({'error_types', 'functions', 'types', 'version'}, api_info)
|
||||
eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_info)
|
||||
end)
|
||||
|
||||
it('fails when called with no arguments', function()
|
||||
|
Loading…
Reference in New Issue
Block a user