Object provider_call(char *method, Array args) { Feature *f = pmap_get(cstr_t)(registered_providers, method); if (!f || !channel_exists(f->channel_id)) { char buf[256]; snprintf(buf, sizeof(buf), "Provider for method \"%s\" is not available", method); vim_report_error(cstr_as_string(buf)); api_free_array(args); return NIL; } Error err = ERROR_INIT; Object result = NIL = channel_send_call(f->channel_id, method, args, &err); if (err.set) { vim_report_error(cstr_as_string(err.msg)); api_free_object(result); return NIL; } return result; }
void remote_ui_init(void) { connected_uis = pmap_new(uint64_t)(); // Add handler for "attach_ui" String method = cstr_as_string("ui_attach"); MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false}; msgpack_rpc_add_method_handler(method, handler); method = cstr_as_string("ui_detach"); handler.fn = remote_ui_detach; msgpack_rpc_add_method_handler(method, handler); method = cstr_as_string("ui_try_resize"); handler.fn = remote_ui_try_resize; msgpack_rpc_add_method_handler(method, handler); } void remote_ui_disconnect(uint64_t channel_id) { UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); if (!ui) { return; } UIData *data = ui->data; // destroy pending screen updates api_free_array(data->buffer); pmap_del(uint64_t)(connected_uis, channel_id); xfree(ui->data); ui_detach(ui); xfree(ui); }
void api_free_object(Object value) { switch (value.type) { case kObjectTypeNil: case kObjectTypeBoolean: case kObjectTypeInteger: case kObjectTypeFloat: case kObjectTypeBuffer: case kObjectTypeWindow: case kObjectTypeTabpage: break; case kObjectTypeString: api_free_string(value.data.string); break; case kObjectTypeArray: api_free_array(value.data.array); break; case kObjectTypeDictionary: api_free_dictionary(value.data.dictionary); break; default: abort(); } }
void ui_event(char *name, Array args) { bool args_consumed = false; ui_call_event(name, args, &args_consumed); if (!args_consumed) { api_free_array(args); } }
void ui_event(char *name, Array args) { bool args_consumed = false; UI_CALL(event, name, args, &args_consumed); if (!args_consumed) { api_free_array(args); } }
void ui_flush(void) { cmdline_ui_flush(); if (pending_cursor_update) { ui_call_grid_cursor_goto(1, row, col); pending_cursor_update = false; } if (pending_mode_info_update) { Array style = mode_style_array(); bool enabled = (*p_guicursor != NUL); ui_call_mode_info_set(enabled, style); api_free_array(style); pending_mode_info_update = false; } if (pending_mode_update) { char *full_name = shape_table[mode_idx].full_name; ui_call_mode_change(cstr_as_string(full_name), mode_idx); pending_mode_update = false; } ui_call_flush(); }