From f926cc32c9262b6254e2843276b951cef9da1afe Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 2 Jul 2024 13:45:50 +0200 Subject: refactor(shada): rework msgpack decoding without msgpack-c This also makes shada reading slightly faster due to avoiding some copying and allocation. Use keysets to drive decoding of msgpack maps for shada entries. --- src/nvim/ui_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 4f36cae4b2..839cf965b0 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -174,7 +174,7 @@ static HlAttrs ui_client_dict2hlattrs(Dictionary 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; } -- cgit From 5931f780e0282ad486fa070bb05b3877cc1d44f0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 11 Sep 2024 17:25:00 -0700 Subject: feat(log): use "ui" as default name for TUI client #30345 The default "session name" for the builtin TUI is "ui". before: INF 2024-09-10T14:57:35.385 hello.sock os_exit:692: Nvim exit: 1 INF 2024-09-10T14:57:35.388 ?.4543 os_exit:692: Nvim exit: 1 after: INF 2024-09-10T14:59:19.919 hello.sock os_exit:692: Nvim exit: 1 INF 2024-09-10T14:59:19.922 ui.5684 os_exit:692: Nvim exit: 1 --- src/nvim/ui_client.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 839cf965b0..cfa79b9d8c 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -22,6 +22,7 @@ #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/tui/tui.h" #include "nvim/tui/tui_defs.h" @@ -126,6 +127,11 @@ 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"); + } + // os_exit() will be invoked when the client channel detaches while (true) { LOOP_PROCESS_EVENTS(&main_loop, resize_events, -1); -- cgit From ff85e54939b0aca34a779a2b6381d09db1858b29 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 18 Sep 2024 04:14:06 -0700 Subject: feat(tui): builtin UI (TUI) sets client info #30397 Problem: The default builtin UI client does not declare its client info. This reduces discoverability and makes it difficult for plugins to identify the UI. Solution: - Call nvim_set_client_info after attaching, as recommended by `:help dev-ui`. - Also set the "pid" field. - Also change `ui_active()` to return a count. Not directly relevant to this commit, but will be useful later. --- src/nvim/ui_client.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index cfa79b9d8c..43ab238716 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -24,6 +24,7 @@ #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" @@ -81,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)); @@ -94,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)); @@ -108,6 +111,40 @@ void ui_client_attach(int width, int height, char *term, bool rgb) 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(); + Dictionary version = { 0 }; + assert(m.data.dictionary.size > 0); + for (size_t i = 0; i < m.data.dictionary.size; i++) { + if (strequal(m.data.dictionary.items[i].key.data, "version")) { + version = m.data.dictionary.items[i].value.data.dictionary; + break; + } else if (i + 1 == m.data.dictionary.size) { + abort(); + } + } + ADD_C(args2, DICTIONARY_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, DICTIONARY_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) @@ -132,6 +169,8 @@ void ui_client_run(bool remote_ui) 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); -- cgit From 737f58e23230ea14f1648ac1fc7f442ea0f8563c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 20 Sep 2024 07:34:50 +0200 Subject: refactor(api)!: rename Dictionary => Dict In the api_info() output: :new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val') ... {'return_type': 'ArrayOf(Integer, 2)', 'name': 'nvim_win_get_position', 'method': v:true, 'parameters': [['Window', 'window']], 'since': 1} The `ArrayOf(Integer, 2)` return type didn't break clients when we added it, which is evidence that clients don't use the `return_type` field, thus renaming Dictionary => Dict in api_info() is not (in practice) a breaking change. --- src/nvim/ui_client.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 43ab238716..adaf3eadb8 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -107,7 +107,7 @@ 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; @@ -120,17 +120,17 @@ void ui_client_attach(int width, int height, char *term, bool rgb) MAXSIZE_TEMP_ARRAY(args2, 5); ADD_C(args2, CSTR_AS_OBJ("nvim-tui")); // name Object m = api_metadata(); - Dictionary version = { 0 }; - assert(m.data.dictionary.size > 0); - for (size_t i = 0; i < m.data.dictionary.size; i++) { - if (strequal(m.data.dictionary.items[i].key.data, "version")) { - version = m.data.dictionary.items[i].value.data.dictionary; + 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.dictionary.size) { + } else if (i + 1 == m.data.dict.size) { abort(); } } - ADD_C(args2, DICTIONARY_OBJ(version)); // version + 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. @@ -141,7 +141,7 @@ void ui_client_attach(int width, int height, char *term, bool rgb) 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, DICTIONARY_OBJ(info)); // attributes + 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"); @@ -215,7 +215,7 @@ 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; -- cgit