diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-19 22:57:13 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-19 22:57:13 +0000 |
commit | 9be89f131f87608f224f0ee06d199fcd09d32176 (patch) | |
tree | 11022dcfa9e08cb4ac5581b16734196128688d48 /src/nvim/ui_client.c | |
parent | ff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff) | |
parent | 88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff) | |
download | rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2 rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/ui_client.c')
-rw-r--r-- | src/nvim/ui_client.c | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 4f36cae4b2..adaf3eadb8 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -22,7 +22,9 @@ #include "nvim/memory_defs.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/channel_defs.h" +#include "nvim/os/os.h" #include "nvim/os/os_defs.h" +#include "nvim/profile.h" #include "nvim/tui/tui.h" #include "nvim/tui/tui_defs.h" #include "nvim/ui.h" @@ -80,12 +82,15 @@ uint64_t ui_client_start_server(int argc, char **argv) return channel->id; } +/// Attaches this client to the UI channel, and sets its client info. void ui_client_attach(int width, int height, char *term, bool rgb) { + // + // nvim_ui_attach + // MAXSIZE_TEMP_ARRAY(args, 3); ADD_C(args, INTEGER_OBJ(width)); ADD_C(args, INTEGER_OBJ(height)); - MAXSIZE_TEMP_DICT(opts, 9); PUT_C(opts, "rgb", BOOLEAN_OBJ(rgb)); PUT_C(opts, "ext_linegrid", BOOLEAN_OBJ(true)); @@ -93,7 +98,6 @@ void ui_client_attach(int width, int height, char *term, bool rgb) if (term) { PUT_C(opts, "term_name", CSTR_AS_OBJ(term)); } - PUT_C(opts, "term_colors", INTEGER_OBJ(t_colors)); if (!ui_client_is_remote) { PUT_C(opts, "stdin_tty", BOOLEAN_OBJ(stdin_isatty)); @@ -103,10 +107,44 @@ void ui_client_attach(int width, int height, char *term, bool rgb) ui_client_forward_stdin = false; // stdin shouldn't be forwarded again #22292 } } - ADD_C(args, DICTIONARY_OBJ(opts)); + ADD_C(args, DICT_OBJ(opts)); rpc_send_event(ui_client_channel_id, "nvim_ui_attach", args); ui_client_attached = true; + + TIME_MSG("nvim_ui_attach"); + + // + // nvim_set_client_info + // + MAXSIZE_TEMP_ARRAY(args2, 5); + ADD_C(args2, CSTR_AS_OBJ("nvim-tui")); // name + Object m = api_metadata(); + Dict version = { 0 }; + assert(m.data.dict.size > 0); + for (size_t i = 0; i < m.data.dict.size; i++) { + if (strequal(m.data.dict.items[i].key.data, "version")) { + version = m.data.dict.items[i].value.data.dict; + break; + } else if (i + 1 == m.data.dict.size) { + abort(); + } + } + ADD_C(args2, DICT_OBJ(version)); // version + ADD_C(args2, CSTR_AS_OBJ("ui")); // type + // We don't send api_metadata.functions as the "methods" because: + // 1. it consumes memory. + // 2. it is unlikely to be useful, since the peer can just call `nvim_get_api`. + // 3. nvim_set_client_info expects a dict instead of an array. + ADD_C(args2, ARRAY_OBJ((Array)ARRAY_DICT_INIT)); // methods + MAXSIZE_TEMP_DICT(info, 9); // attributes + PUT_C(info, "website", CSTR_AS_OBJ("https://neovim.io")); + PUT_C(info, "license", CSTR_AS_OBJ("Apache 2")); + PUT_C(info, "pid", INTEGER_OBJ(os_get_pid())); + ADD_C(args2, DICT_OBJ(info)); // attributes + rpc_send_event(ui_client_channel_id, "nvim_set_client_info", args2); + + TIME_MSG("nvim_set_client_info"); } void ui_client_detach(void) @@ -126,6 +164,13 @@ void ui_client_run(bool remote_ui) ui_client_attach(width, height, term, rgb); + // TODO(justinmk): this is for log_spec. Can remove this after nvim_log #7062 is merged. + if (os_env_exists("__NVIM_TEST_LOG")) { + ELOG("test log message"); + } + + time_finish(); + // os_exit() will be invoked when the client channel detaches while (true) { LOOP_PROCESS_EVENTS(&main_loop, resize_events, -1); @@ -170,11 +215,11 @@ Object handle_ui_client_redraw(uint64_t channel_id, Array args, Arena *arena, Er return NIL; } -static HlAttrs ui_client_dict2hlattrs(Dictionary d, bool rgb) +static HlAttrs ui_client_dict2hlattrs(Dict d, bool rgb) { Error err = ERROR_INIT; Dict(highlight) dict = KEYDICT_INIT; - if (!api_dict_to_keydict(&dict, KeyDict_highlight_get_field, d, &err)) { + if (!api_dict_to_keydict(&dict, DictHash(highlight), d, &err)) { // TODO(bfredl): log "err" return HLATTRS_INIT; } |