diff options
-rwxr-xr-x | src/nvim/CMakeLists.txt | 9 | ||||
-rwxr-xr-x | src/nvim/generators/gen_api_ui_events.lua | 32 | ||||
-rw-r--r-- | src/nvim/map.c | 2 | ||||
-rw-r--r-- | src/nvim/map.h | 2 | ||||
-rw-r--r-- | src/nvim/ui_client.c | 35 | ||||
-rw-r--r-- | src/nvim/ui_client.h | 4 |
6 files changed, 40 insertions, 44 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 34d112a756..8e17f94abc 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -39,7 +39,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_REDRAW ${GENERATED_DIR}/ui_events_redraw.generated.h) +set(GENERATED_UI_EVENTS_CLIENT ${GENERATED_DIR}/ui_events_client.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) @@ -272,7 +272,7 @@ foreach(sfile ${NVIM_SOURCES} "${GENERATED_UI_EVENTS_REMOTE}" "${GENERATED_UI_EVENTS_BRIDGE}" "${GENERATED_KEYSETS}" - "${GENERATED_UI_EVENTS_REDRAW}" + "${GENERATED_UI_EVENTS_CLIENT}" ) get_filename_component(full_d ${sfile} PATH) file(RELATIVE_PATH d "${CMAKE_CURRENT_LIST_DIR}" "${full_d}") @@ -370,7 +370,7 @@ add_custom_command( ${GENERATED_UI_EVENTS_REMOTE} ${GENERATED_UI_EVENTS_BRIDGE} ${GENERATED_UI_EVENTS_METADATA} - ${GENERATED_UI_EVENTS_REDRAW} + ${GENERATED_UI_EVENTS_CLIENT} COMMAND ${LUA_PRG} ${API_UI_EVENTS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/api/ui_events.in.h ${GENERATED_UI_EVENTS} @@ -378,8 +378,7 @@ add_custom_command( ${GENERATED_UI_EVENTS_REMOTE} ${GENERATED_UI_EVENTS_BRIDGE} ${GENERATED_UI_EVENTS_METADATA} - ${GENERATED_UI_EVENTS_REDRAW} - + ${GENERATED_UI_EVENTS_CLIENT} DEPENDS ${API_UI_EVENTS_GENERATOR} ${GENERATOR_C_GRAMMAR} diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua index 3cb63c3837..cdf4538e9f 100755 --- a/src/nvim/generators/gen_api_ui_events.lua +++ b/src/nvim/generators/gen_api_ui_events.lua @@ -10,9 +10,9 @@ local call_output = io.open(arg[4], 'wb') local remote_output = io.open(arg[5], 'wb') local bridge_output = io.open(arg[6], 'wb') local metadata_output = io.open(arg[7], 'wb') -local redraw_output = io.open(arg[8], 'wb') +local client_output = io.open(arg[8], 'wb') -c_grammar = require('generators.c_grammar') +local c_grammar = require('generators.c_grammar') local events = c_grammar.grammar:match(input:read('*all')) local function write_signature(output, ev, prefix, notype) @@ -51,7 +51,7 @@ local function write_arglist(output, ev, need_copy) end end -function extract_and_write_arglist(output, ev) +local function extract_and_write_arglist(output, ev) local hlattrs_args_count = 0 for j = 1, #ev.parameters do local param = ev.parameters[j] @@ -59,7 +59,7 @@ function extract_and_write_arglist(output, ev) output:write(' '..kind..' arg_'..j..' = ') if kind == 'HlAttrs' then -- The first HlAttrs argument is rgb_attrs and second is cterm_attrs - output:write('redraw_dict2hlattrs(args.items['..(j-1)..'].data.dictionary, '..(hlattrs_args_count == 0 and 'true' or 'false')..');\n') + output:write('ui_client_dict2hlattrs(args.items['..(j-1)..'].data.dictionary, '..(hlattrs_args_count == 0 and 'true' or 'false')..');\n') hlattrs_args_count = hlattrs_args_count + 1 elseif kind == 'Object' then output:write('args.items['..(j-1)..'];\n') @@ -69,7 +69,7 @@ function extract_and_write_arglist(output, ev) end end -function call_ui_event_method(output, ev) +local function call_ui_event_method(output, ev) output:write(' ui_call_'..ev.name..'(') for j = 1, #ev.parameters do output:write('arg_'..j) @@ -192,16 +192,16 @@ for i = 1, #events do end if (not ev.remote_only) and (not ev.noexport) and (not ev.client_impl) then - redraw_output:write('void ui_redraw_event_'..ev.name..'(Array args)\n{\n') - extract_and_write_arglist(redraw_output, ev) - call_ui_event_method(redraw_output, ev) - redraw_output:write('}\n\n') + client_output:write('void ui_client_event_'..ev.name..'(Array args)\n{\n') + extract_and_write_arglist(client_output, ev) + call_ui_event_method(client_output, ev) + client_output:write('}\n\n') end end --- Generate the map_init method for redraw handlers -redraw_output:write([[ -void redraw_methods_table_init(void) +-- Generate the map_init method for client handlers +client_output:write([[ +void ui_client_methods_table_init(void) { ]]) @@ -209,19 +209,19 @@ void redraw_methods_table_init(void) for i = 1, #events do local fn = events[i] if (not fn.noexport) and ((not fn.remote_only) or fn.client_impl) then - redraw_output:write(' add_redraw_event_handler('.. + client_output:write(' add_ui_client_event_handler('.. '(String) {.data = "'..fn.name..'", '.. '.size = sizeof("'..fn.name..'") - 1}, '.. - '(ApiRedrawWrapper) ui_redraw_event_'..fn.name..');\n') + '(UIClientHandler) ui_client_event_'..fn.name..');\n') end end -redraw_output:write('\n}\n\n') +client_output:write('\n}\n\n') proto_output:close() call_output:close() remote_output:close() -redraw_output:close() +client_output:close() -- don't expose internal attributes like "impl_name" in public metadata local exported_attributes = {'name', 'parameters', diff --git a/src/nvim/map.c b/src/nvim/map.c index 260a27c485..b3f48ad5d6 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -179,7 +179,7 @@ MAP_IMPL(HlEntry, int, DEFAULT_INITIALIZER) MAP_IMPL(String, handle_T, 0) MAP_IMPL(String, int, DEFAULT_INITIALIZER) MAP_IMPL(int, String, DEFAULT_INITIALIZER) -MAP_IMPL(String, ApiRedrawWrapper, NULL) +MAP_IMPL(String, UIClientHandler, NULL) MAP_IMPL(ColorKey, ColorItem, COLOR_ITEM_INITIALIZER) diff --git a/src/nvim/map.h b/src/nvim/map.h index 0fa3fbd83d..693ef50127 100644 --- a/src/nvim/map.h +++ b/src/nvim/map.h @@ -49,7 +49,7 @@ MAP_DECLS(HlEntry, int) MAP_DECLS(String, handle_T) MAP_DECLS(String, int) MAP_DECLS(int, String) -MAP_DECLS(String, ApiRedrawWrapper) +MAP_DECLS(String, UIClientHandler) MAP_DECLS(ColorKey, ColorItem) diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index c13bfc2d07..daae257027 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -16,11 +16,11 @@ #include "nvim/highlight.h" #include "nvim/screen.h" -static Map(String, ApiRedrawWrapper) redraw_methods = MAP_INIT; +static Map(String, UIClientHandler) ui_client_handlers = MAP_INIT; -static void add_redraw_event_handler(String method, ApiRedrawWrapper handler) +static void add_ui_client_event_handler(String method, UIClientHandler handler) { - map_put(String, ApiRedrawWrapper)(&redraw_methods, method, handler); + map_put(String, UIClientHandler)(&ui_client_handlers, method, handler); } void ui_client_init(uint64_t chan) @@ -40,17 +40,16 @@ void ui_client_init(uint64_t chan) rpc_send_event(chan, "nvim_ui_attach", args); msgpack_rpc_add_redraw(); // GAME! - redraw_methods_table_init(); + // TODO(bfredl): use a keyset instead + ui_client_methods_table_init(); ui_client_channel_id = chan; } /// Handler for "redraw" events sent by the NVIM server /// -/// This is just a stub. The mentioned functionality will be implemented. -/// -/// This function will be called by handle_request (in msgpack_rpc/channle.c) +/// This function will be called by handle_request (in msgpack_rpc/channel.c) /// The individual ui_events sent by the server are individually handled -/// by their respective handlers defined in ui_events_redraw.generated.h +/// by their respective handlers defined in ui_events_client.generated.h /// /// @note The "flush" event is called only once and only after handling all /// the other events @@ -63,21 +62,19 @@ Object ui_client_handle_redraw(uint64_t channel_id, Array args, Error *error) Array call = args.items[i].data.array; String name = call.items[0].data.string; - ApiRedrawWrapper handler = map_get(String, ApiRedrawWrapper)(&redraw_methods, name); + UIClientHandler handler = map_get(String, UIClientHandler)(&ui_client_handlers, name); if (!handler) { - ELOG("No redraw handler by name: %s", name.size ? name.data : "<empty>"); + ELOG("No ui client handler for %s", name.size ? name.data : "<empty>"); continue; } // fprintf(stderr, "%s: %zu\n", name.data, call.size-1); - - DLOG("Invoke redraw handler by name: %s", name.data); + DLOG("Invoke ui client handler for %s", name.data); for (size_t j = 1; j < call.size; j++) { - Array internal_call_args = call.items[j].data.array; - handler(internal_call_args); + handler(call.items[j].data.array); } - } + return NIL; } @@ -93,11 +90,11 @@ void ui_client_execute(uint64_t chan) getout(0); } -static HlAttrs redraw_dict2hlattrs(Dictionary redraw_dict, bool rgb) +static HlAttrs ui_client_dict2hlattrs(Dictionary d, bool rgb) { Error err = ERROR_INIT; Dict(highlight) dict = { 0 }; - if (!api_dict_to_keydict(&dict, KeyDict_highlight_get_field, redraw_dict, &err)) { + if (!api_dict_to_keydict(&dict, KeyDict_highlight_get_field, d, &err)) { // TODO(bfredl): log "err" return HLATTRS_INIT; } @@ -105,10 +102,10 @@ static HlAttrs redraw_dict2hlattrs(Dictionary redraw_dict, bool rgb) } #ifdef INCLUDE_GENERATED_DECLARATIONS -#include "ui_events_redraw.generated.h" +#include "ui_events_client.generated.h" #endif -void ui_redraw_event_grid_line(Array args) +void ui_client_event_grid_line(Array args) { Integer grid = args.items[0].data.integer; Integer row = args.items[1].data.integer; diff --git a/src/nvim/ui_client.h b/src/nvim/ui_client.h index a120f2b334..253deecc52 100644 --- a/src/nvim/ui_client.h +++ b/src/nvim/ui_client.h @@ -3,11 +3,11 @@ #include "nvim/api/private/defs.h" -typedef void (*ApiRedrawWrapper)(Array args); +typedef void (*UIClientHandler)(Array args); #ifdef INCLUDE_GENERATED_DECLARATIONS #include "ui_client.h.generated.h" -#include "ui_events_redraw.h.generated.h" +#include "ui_events_client.h.generated.h" #endif #endif // NVIM_UI_CLIENT_H |