From 28e26e05bc4cd2bd8e1abc2dd4d720fd9199456d Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 8 Feb 2023 16:24:33 +0100 Subject: perf(ui): mitigate redraw latency regression from TUI refactor While the new RPC encoder/decoder implementation in general should have less overhead than the deleted UIBridge serializer previously used for the TUI, it regresses on redraw latency in one important aspect. The old bridge implementation allowed the TUI to process a previous screen line internally in parallel with the main thread rendering the next one in win_line etc. As printing the escape sequences in highlighted cells has a considerable hit in profiles, this has a substantial effect on redraw latency. The RPC implementation, however, waits with sending any data until either a flush, or the buffer is full. This change lowers the granularity of communication again, using an adjustable threshold counted in number of cell events (discounting long repeats and clearing as maximum a single extra event). The current value is guesstimated to something simple on a reasonable scale, which should be bigger than a single line, but multiple events for a big multi-window screen. --- src/nvim/api/ui.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e67607a7e4..3ad625234c 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -202,6 +202,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona data->flushed_events = false; data->ncalls_pos = NULL; data->ncalls = 0; + data->ncells_pending = 0; data->buf_wptr = data->buf; data->temp_buf = NULL; data->wildmenu_active = false; @@ -854,18 +855,25 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int mpack_uint(buf, repeat); } } + data->ncells_pending += MIN(repeat, 2); last_hl = attrs[i]; repeat = 0; } } if (endcol < clearcol) { nelem++; + data->ncells_pending += 1; mpack_array(buf, 3); mpack_str(buf, " "); mpack_uint(buf, (uint32_t)clearattr); mpack_uint(buf, (uint32_t)(clearcol - endcol)); } mpack_w2(&lenpos, nelem); + + if (data->ncells_pending > 500) { + // pass of cells to UI to let it start processing them + remote_ui_flush_buf(ui); + } } else { for (int i = 0; i < endcol - startcol; i++) { remote_ui_cursor_goto(ui, row, startcol + i); @@ -917,6 +925,8 @@ void remote_ui_flush_buf(UI *ui) // we have sent events to the client, but possibly not yet the final "flush" // event. data->flushed_events = true; + + data->ncells_pending = 0; } /// An intentional flush (vsync) when Nvim is finished redrawing the screen -- cgit From 41ebe41b62921142bb486e5f30bd2fa9f53f1700 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 12 Feb 2023 19:02:14 +0800 Subject: fix(ui-ext): force cursor update after resize in char-based UI Neither ui/screen.lua nor Neovim Qt keep cursor position after resizing. --- src/nvim/api/ui.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 3ad625234c..8f5465db77 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -645,6 +645,8 @@ void remote_ui_grid_resize(UI *ui, Integer grid, Integer width, Integer height) Array args = data->call_buf; if (ui->ui_ext[kUILinegrid]) { ADD_C(args, INTEGER_OBJ(grid)); + } else { + data->client_col = -1; // force cursor update } ADD_C(args, INTEGER_OBJ(width)); ADD_C(args, INTEGER_OBJ(height)); -- cgit From ff3d04b75b4a9314815c37d53ebc4d035a043335 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 08:07:38 -0500 Subject: refactor(api): VALIDATE macros #22256 - VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args --- src/nvim/api/ui.c | 66 +++++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 8f5465db77..61f2c881b3 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -12,6 +12,7 @@ #include "klib/kvec.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" +#include "nvim/api/private/validate.h" #include "nvim/api/ui.h" #include "nvim/autocmd.h" #include "nvim/channel.h" @@ -291,22 +292,20 @@ void nvim_ui_set_option(uint64_t channel_id, String name, Object value, Error *e ui_set_option(ui, false, name, value, error); } -static void ui_set_option(UI *ui, bool init, String name, Object value, Error *error) +static void ui_set_option(UI *ui, bool init, String name, Object value, Error *err) { if (strequal(name.data, "override")) { - if (value.type != kObjectTypeBoolean) { - api_set_error(error, kErrorTypeValidation, "override must be a Boolean"); + VALIDATE_T("override", kObjectTypeBoolean, value.type, { return; - } + }); ui->override = value.data.boolean; return; } if (strequal(name.data, "rgb")) { - if (value.type != kObjectTypeBoolean) { - api_set_error(error, kErrorTypeValidation, "rgb must be a Boolean"); + VALIDATE_T("rgb", kObjectTypeBoolean, value.type, { return; - } + }); ui->rgb = value.data.boolean; // A little drastic, but only takes effect for legacy uis. For linegrid UI // only changes metadata for nvim_list_uis(), no refresh needed. @@ -317,62 +316,56 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e } if (strequal(name.data, "term_name")) { - if (value.type != kObjectTypeString) { - api_set_error(error, kErrorTypeValidation, "term_name must be a String"); + VALIDATE_T("term_name", kObjectTypeString, value.type, { return; - } + }); set_tty_option("term", string_to_cstr(value.data.string)); return; } if (strequal(name.data, "term_colors")) { - if (value.type != kObjectTypeInteger) { - api_set_error(error, kErrorTypeValidation, "term_colors must be a Integer"); + VALIDATE_T("term_colors", kObjectTypeInteger, value.type, { return; - } + }); t_colors = (int)value.data.integer; return; } if (strequal(name.data, "term_background")) { - if (value.type != kObjectTypeString) { - api_set_error(error, kErrorTypeValidation, "term_background must be a String"); + VALIDATE_T("term_background", kObjectTypeString, value.type, { return; - } + }); set_tty_background(value.data.string.data); return; } if (strequal(name.data, "stdin_fd")) { - if (value.type != kObjectTypeInteger || value.data.integer < 0) { - api_set_error(error, kErrorTypeValidation, "stdin_fd must be a non-negative Integer"); + VALIDATE_T("stdin_fd", kObjectTypeInteger, value.type, { return; - } - - if (starting != NO_SCREEN) { - api_set_error(error, kErrorTypeValidation, - "stdin_fd can only be used with first attached ui"); + }); + VALIDATE_INT((value.data.integer >= 0), "stdin_fd", value.data.integer, { return; - } + }); + VALIDATE((starting == NO_SCREEN), "%s", "stdin_fd can only be used with first attached UI", { + return; + }); stdin_fd = (int)value.data.integer; return; } if (strequal(name.data, "stdin_tty")) { - if (value.type != kObjectTypeBoolean) { - api_set_error(error, kErrorTypeValidation, "stdin_tty must be a Boolean"); + VALIDATE_T("stdin_tty", kObjectTypeBoolean, value.type, { return; - } + }); stdin_isatty = value.data.boolean; return; } if (strequal(name.data, "stdout_tty")) { - if (value.type != kObjectTypeBoolean) { - api_set_error(error, kErrorTypeValidation, "stdout_tty must be a Boolean"); + VALIDATE_T("stdout_tty", kObjectTypeBoolean, value.type, { return; - } + }); stdout_isatty = value.data.boolean; return; } @@ -383,17 +376,15 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e for (UIExtension i = 0; i < kUIExtCount; i++) { if (strequal(name.data, ui_ext_names[i]) || (i == kUIPopupmenu && is_popupmenu)) { - if (value.type != kObjectTypeBoolean) { - api_set_error(error, kErrorTypeValidation, "%s must be a Boolean", - name.data); + VALIDATE_EXP((value.type == kObjectTypeBoolean), name.data, "Boolean", + api_typename(value.type), { return; - } + }); bool boolval = value.data.boolean; if (!init && i == kUILinegrid && boolval != ui->ui_ext[i]) { // There shouldn't be a reason for an UI to do this ever // so explicitly don't support this. - api_set_error(error, kErrorTypeValidation, - "ext_linegrid option cannot be changed"); + api_set_error(err, kErrorTypeValidation, "ext_linegrid option cannot be changed"); } ui->ui_ext[i] = boolval; if (!init) { @@ -403,8 +394,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e } } - api_set_error(error, kErrorTypeValidation, "No such UI option: %s", - name.data); + api_set_error(err, kErrorTypeValidation, "No such UI option: %s", name.data); } /// Tell Nvim to resize a grid. Triggers a grid_resize event with the requested -- cgit From b62c0c8d9c22ae7fc9ee200733f8312efa6dbced Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 20 Feb 2023 08:12:59 +0100 Subject: docs: fix typos (#21961) Co-authored-by: Ben Morgan --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 61f2c881b3..3c3c3008f4 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -254,7 +254,7 @@ void nvim_ui_detach(uint64_t channel_id, Error *err) remote_ui_disconnect(channel_id); } -// TODO(bfredl): use me to detach a specifc ui from the server +// TODO(bfredl): use me to detach a specific ui from the server void remote_ui_stop(UI *ui) {} -- cgit From 344a1ee8e6b7d78120f8393d1babfd285e866334 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 22 Feb 2023 00:07:26 +0800 Subject: docs: fix typos (#22353) --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 3c3c3008f4..f6dee066dc 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -382,7 +382,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e }); bool boolval = value.data.boolean; if (!init && i == kUILinegrid && boolval != ui->ui_ext[i]) { - // There shouldn't be a reason for an UI to do this ever + // There shouldn't be a reason for a UI to do this ever // so explicitly don't support this. api_set_error(err, kErrorTypeValidation, "ext_linegrid option cannot be changed"); } -- cgit From 7f424e2b65779c59fc0cac3cc7508ba2ec07f200 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 23 Feb 2023 18:29:36 +0100 Subject: feat(api): more fields in nvim_list_uis Problem: nvim_list_uis does not report all ":help ui-option" fields. Solution: Store ":help ui-option" fields on the `UI` object and update ui_array. --- src/nvim/api/ui.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index f6dee066dc..00fd2781ff 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -113,6 +113,10 @@ void remote_ui_disconnect(uint64_t channel_id) kv_destroy(data->call_buf); pmap_del(uint64_t)(&connected_uis, channel_id); ui_detach_impl(ui, channel_id); + + // Destroy `ui`. + XFREE_CLEAR(ui->term_name); + XFREE_CLEAR(ui->term_background); xfree(ui); } @@ -163,15 +167,9 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona UI *ui = xcalloc(1, sizeof(UI)); ui->width = (int)width; ui->height = (int)height; - ui->pum_nlines = 0; - ui->pum_pos = false; - ui->pum_width = 0.0; - ui->pum_height = 0.0; ui->pum_row = -1.0; ui->pum_col = -1.0; ui->rgb = true; - ui->override = false; - CLEAR_FIELD(ui->ui_ext); for (size_t i = 0; i < options.size; i++) { @@ -320,6 +318,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; }); set_tty_option("term", string_to_cstr(value.data.string)); + ui->term_name = string_to_cstr(value.data.string); return; } @@ -328,6 +327,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; }); t_colors = (int)value.data.integer; + ui->term_colors = (int)value.data.integer; return; } @@ -336,6 +336,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; }); set_tty_background(value.data.string.data); + ui->term_background = string_to_cstr(value.data.string); return; } @@ -351,6 +352,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e }); stdin_fd = (int)value.data.integer; + ui->stdin_fd = (int)value.data.integer; return; } @@ -359,6 +361,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; }); stdin_isatty = value.data.boolean; + ui->stdin_tty = value.data.boolean; return; } @@ -367,6 +370,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; }); stdout_isatty = value.data.boolean; + ui->stdout_tty = value.data.boolean; return; } -- cgit From ce597235a26839826de88ecd8b949ec54c310fbd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Feb 2023 16:31:05 +0100 Subject: feat(ui): restore has('gui_running') Problem: has('gui_running') is still common in the wild and our answer has changed over time, causing frustration. https://github.com/vimpostor/vim-tpipeline/commit/95a6ccbe9f33bc42dd4cee45731d8bc3fbcd92d1 Solution: Use stdin_tty/stdout_tty to decide if a UI is (not) a GUI. --- src/nvim/api/ui.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 00fd2781ff..a8f5d2e070 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -352,7 +352,6 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e }); stdin_fd = (int)value.data.integer; - ui->stdin_fd = (int)value.data.integer; return; } -- cgit From c0fe6c040e19ef9102a8507ffcbd88b83186326a Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Thu, 23 Mar 2023 16:31:39 +0700 Subject: feat(api): add nvim_get_hl (#22693) Problem: no way of getting all highlight group definitions in a namespace. Solution: add `nvim_get_hl()`, deprecate `nvim_get_hl_by_name()` and `nvim_get_hl_by_id()`. --- src/nvim/api/ui.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index a8f5d2e070..201989aee5 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -727,8 +727,8 @@ void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAttrs cte ADD_C(args, INTEGER_OBJ(id)); MAXSIZE_TEMP_DICT(rgb, HLATTRS_DICT_SIZE); MAXSIZE_TEMP_DICT(cterm, HLATTRS_DICT_SIZE); - hlattrs2dict(&rgb, rgb_attrs, true); - hlattrs2dict(&cterm, rgb_attrs, false); + hlattrs2dict(&rgb, rgb_attrs, true, false); + hlattrs2dict(&cterm, rgb_attrs, false, false); ADD_C(args, DICTIONARY_OBJ(rgb)); ADD_C(args, DICTIONARY_OBJ(cterm)); @@ -751,7 +751,7 @@ void remote_ui_highlight_set(UI *ui, int id) } data->hl_id = id; MAXSIZE_TEMP_DICT(dict, HLATTRS_DICT_SIZE); - hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb); + hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb, false); ADD_C(args, DICTIONARY_OBJ(dict)); push_call(ui, "highlight_set", args); } @@ -950,7 +950,7 @@ static Array translate_contents(UI *ui, Array contents, Arena *arena) int attr = (int)item.items[0].data.integer; if (attr) { Dictionary rgb_attrs = arena_dict(arena, HLATTRS_DICT_SIZE); - hlattrs2dict(&rgb_attrs, syn_attr2entry(attr), ui->rgb); + hlattrs2dict(&rgb_attrs, syn_attr2entry(attr), ui->rgb, false); ADD(new_item, DICTIONARY_OBJ(rgb_attrs)); } else { ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); -- cgit From 6d267ad30cf539f520b46e3c92939f7031ce116f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 23 Mar 2023 12:44:05 +0100 Subject: fix(api): make nvim_get_hl return 'cterm' attrs properly --- src/nvim/api/ui.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 201989aee5..5dd858a6a9 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -727,8 +727,8 @@ void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAttrs cte ADD_C(args, INTEGER_OBJ(id)); MAXSIZE_TEMP_DICT(rgb, HLATTRS_DICT_SIZE); MAXSIZE_TEMP_DICT(cterm, HLATTRS_DICT_SIZE); - hlattrs2dict(&rgb, rgb_attrs, true, false); - hlattrs2dict(&cterm, rgb_attrs, false, false); + hlattrs2dict(&rgb, NULL, rgb_attrs, true, false); + hlattrs2dict(&cterm, NULL, rgb_attrs, false, false); ADD_C(args, DICTIONARY_OBJ(rgb)); ADD_C(args, DICTIONARY_OBJ(cterm)); @@ -751,7 +751,7 @@ void remote_ui_highlight_set(UI *ui, int id) } data->hl_id = id; MAXSIZE_TEMP_DICT(dict, HLATTRS_DICT_SIZE); - hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb, false); + hlattrs2dict(&dict, NULL, syn_attr2entry(id), ui->rgb, false); ADD_C(args, DICTIONARY_OBJ(dict)); push_call(ui, "highlight_set", args); } @@ -950,7 +950,7 @@ static Array translate_contents(UI *ui, Array contents, Arena *arena) int attr = (int)item.items[0].data.integer; if (attr) { Dictionary rgb_attrs = arena_dict(arena, HLATTRS_DICT_SIZE); - hlattrs2dict(&rgb_attrs, syn_attr2entry(attr), ui->rgb, false); + hlattrs2dict(&rgb_attrs, NULL, syn_attr2entry(attr), ui->rgb, false); ADD(new_item, DICTIONARY_OBJ(rgb_attrs)); } else { ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/api/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 5dd858a6a9..edf13b073c 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -843,7 +843,7 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int uint32_t csize = (repeat > 1) ? 3 : ((attrs[i] != last_hl) ? 2 : 1); nelem++; mpack_array(buf, csize); - mpack_str(buf, (const char *)chunk[i]); + mpack_str(buf, chunk[i]); if (csize >= 2) { mpack_uint(buf, (uint32_t)attrs[i]); if (csize >= 3) { @@ -873,7 +873,7 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int for (int i = 0; i < endcol - startcol; i++) { remote_ui_cursor_goto(ui, row, startcol + i); remote_ui_highlight_set(ui, attrs[i]); - remote_ui_put(ui, (const char *)chunk[i]); + remote_ui_put(ui, chunk[i]); if (utf_ambiguous_width(utf_ptr2char((char *)chunk[i]))) { data->client_col = -1; // force cursor update } -- cgit From 706f871014b46300180156590ff269ee38473989 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 19 Apr 2023 17:04:00 +0100 Subject: build: update uncrustify to 0.76 --- src/nvim/api/ui.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index edf13b073c..bd3482c85f 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -254,7 +254,8 @@ void nvim_ui_detach(uint64_t channel_id, Error *err) // TODO(bfredl): use me to detach a specific ui from the server void remote_ui_stop(UI *ui) -{} +{ +} void nvim_ui_try_resize(uint64_t channel_id, Integer width, Integer height, Error *err) FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY -- cgit From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index bd3482c85f..532c3054ab 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -111,7 +111,7 @@ void remote_ui_disconnect(uint64_t channel_id) } UIData *data = ui->data; kv_destroy(data->call_buf); - pmap_del(uint64_t)(&connected_uis, channel_id); + pmap_del(uint64_t)(&connected_uis, channel_id, NULL); ui_detach_impl(ui, channel_id); // Destroy `ui`. -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 532c3054ab..e98c589189 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -795,7 +795,7 @@ void remote_ui_put(UI *ui, const char *cell) UIData *data = ui->data; data->client_col++; Array args = data->call_buf; - ADD_C(args, STRING_OBJ(cstr_as_string((char *)cell))); + ADD_C(args, CSTR_AS_OBJ((char *)cell)); push_call(ui, "put", args); } -- cgit From 981acc2922ce9a5f214ba14acbb1e444748855f2 Mon Sep 17 00:00:00 2001 From: Ricky Zhou Date: Thu, 1 Jun 2023 02:15:14 -0700 Subject: fix(ui): propagate line wrapping state on grid_line events This fixes the TUI's line-wrapping behavior, which was broken with the migration to the msgpack-based UI protocol (see https://github.com/neovim/neovim/issues/7369#issuecomment-1571812273). --- src/nvim/api/ui.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e98c589189..861ce100cd 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -73,6 +73,11 @@ static void mpack_uint(char **buf, uint32_t val) } } +static void mpack_bool(char **buf, bool val) +{ + mpack_w(buf, 0xc2 | val); +} + static void mpack_array(char **buf, uint32_t len) { if (len < 0x10) { @@ -809,7 +814,7 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int data->ncalls++; char **buf = &data->buf_wptr; - mpack_array(buf, 4); + mpack_array(buf, 5); mpack_uint(buf, (uint32_t)grid); mpack_uint(buf, (uint32_t)row); mpack_uint(buf, (uint32_t)startcol); @@ -823,17 +828,20 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int repeat++; if (i == ncells - 1 || attrs[i] != attrs[i + 1] || strcmp(chunk[i], chunk[i + 1]) != 0) { - if (UI_BUF_SIZE - BUF_POS(data) < 2 * (1 + 2 + sizeof(schar_T) + 5 + 5)) { + if (UI_BUF_SIZE - BUF_POS(data) < 2 * (1 + 2 + sizeof(schar_T) + 5 + 5) + 1) { // close to overflowing the redraw buffer. finish this event, // flush, and start a new "grid_line" event at the current position. // For simplicity leave place for the final "clear" element // as well, hence the factor of 2 in the check. mpack_w2(&lenpos, nelem); + + // We only ever set the wrap field on the final "grid_line" event for the line. + mpack_bool(buf, false); remote_ui_flush_buf(ui); prepare_call(ui, "grid_line"); data->ncalls++; - mpack_array(buf, 4); + mpack_array(buf, 5); mpack_uint(buf, (uint32_t)grid); mpack_uint(buf, (uint32_t)row); mpack_uint(buf, (uint32_t)startcol + (uint32_t)i - repeat + 1); @@ -865,9 +873,10 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int mpack_uint(buf, (uint32_t)(clearcol - endcol)); } mpack_w2(&lenpos, nelem); + mpack_bool(buf, flags & kLineFlagWrap); if (data->ncells_pending > 500) { - // pass of cells to UI to let it start processing them + // pass off cells to UI to let it start processing them remote_ui_flush_buf(ui); } } else { -- cgit From a8cfdf43bc6226e32679ec59769ea3e48ca26193 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 07:16:41 +0800 Subject: fix(events): trigger VimResume on next UI request (#24426) --- src/nvim/api/ui.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 861ce100cd..9fa5a89407 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -215,6 +215,8 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona pmap_put(uint64_t)(&connected_uis, channel_id, ui); ui_attach_impl(ui, channel_id); + + may_trigger_vim_suspend_resume(false); } /// @deprecated @@ -237,6 +239,10 @@ void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error) return; } + if (gained) { + may_trigger_vim_suspend_resume(false); + } + do_autocmd_focusgained((bool)gained); } -- cgit From 0c86828ac57429e3dea1bb4a9e686dc4f0dc9ddb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 2 Sep 2023 18:50:12 +0800 Subject: fix(ui): avoid ambiguity about chunk that clears part of line (#24982) Co-authored-by: bfredl --- src/nvim/api/ui.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 9fa5a89407..891c81d470 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -830,6 +830,7 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int size_t ncells = (size_t)(endcol - startcol); int last_hl = -1; uint32_t nelem = 0; + bool was_space = false; for (size_t i = 0; i < ncells; i++) { repeat++; if (i == ncells - 1 || attrs[i] != attrs[i + 1] @@ -868,9 +869,12 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int data->ncells_pending += MIN(repeat, 2); last_hl = attrs[i]; repeat = 0; + was_space = strequal(chunk[i], " "); } } - if (endcol < clearcol) { + // If the last chunk was all spaces, add a clearing chunk even if there are + // no more cells to clear, so there is no ambiguity about what to clear. + if (endcol < clearcol || was_space) { nelem++; data->ncells_pending += 1; mpack_array(buf, 3); -- cgit From 5970157e1d22fd5e05ae5d3bd949f807fb7a744c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 May 2023 16:08:06 +0200 Subject: refactor(map): enhanced implementation, Clean Code™, etc etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type. --- src/nvim/api/ui.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 891c81d470..70c97be984 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -136,7 +136,7 @@ void remote_ui_wait_for_attach(void) } LOOP_PROCESS_EVENTS_UNTIL(&main_loop, channel->events, -1, - pmap_has(uint64_t)(&connected_uis, CHAN_STDIO)); + map_has(uint64_t, &connected_uis, CHAN_STDIO)); } /// Activates UI events on the channel. @@ -158,7 +158,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona Error *err) FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { - if (pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, "UI already attached to channel: %" PRId64, channel_id); return; @@ -233,7 +233,7 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height, Boolean enabl void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error) FUNC_API_SINCE(11) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(error, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; @@ -255,7 +255,7 @@ void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error) void nvim_ui_detach(uint64_t channel_id, Error *err) FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; @@ -271,7 +271,7 @@ void remote_ui_stop(UI *ui) void nvim_ui_try_resize(uint64_t channel_id, Integer width, Integer height, Error *err) FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; @@ -292,7 +292,7 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width, Integer height, Erro void nvim_ui_set_option(uint64_t channel_id, String name, Object value, Error *error) FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(error, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; @@ -426,7 +426,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width, I Error *err) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; @@ -448,7 +448,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width, I void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; @@ -489,7 +489,7 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa Error *err) FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY { - if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + if (!map_has(uint64_t, &connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, "UI not attached to channel: %" PRId64, channel_id); return; -- cgit From 8da986ea877b07a5eb117446f410f2a7fc8cd9cb Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 13 Sep 2023 13:39:18 +0200 Subject: refactor(grid): change schar_T representation to be more compact Previously, a screen cell would occupy 28+4=32 bytes per cell as we always made space for up to MAX_MCO+1 codepoints in a cell. As an example, even a pretty modest 50*80 screen would consume 50*80*2*32 = 256000, i e a quarter megabyte With the factor of two due to the TUI side buffer, and even more when using msg_grid and/or ext_multigrid. This instead stores a 4-byte union of either: - a valid UTF-8 sequence up to 4 bytes - an escape char which is invalid UTF-8 (0xFF) plus a 24-bit index to a glyph cache This avoids allocating space for huge composed glyphs _upfront_, while still keeping rendering such glyphs reasonably fast (1 hash table lookup + one plain index lookup). If the same large glyphs are using repeatedly on the screen, this is still a net reduction of memory/cache consumption. The only case which really gets worse is if you blast the screen full with crazy emojis and zalgo text and even this case only leads to 4 extra bytes per char. When only <= 4-byte glyphs are used, plus the 4-byte attribute code, i e 8 bytes in total there is a factor of four reduction of memory use. Memory which will be quite hot in cache as the screen buffer is scanned over in win_line() buffer text drawing A slight complication is that the representation depends on host byte order. I've tested this manually by compling and running this in qemu-s390x and it works fine. We might add a qemu based solution to CI at some point. --- src/nvim/api/ui.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 70c97be984..0ea2310042 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -833,8 +833,7 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int bool was_space = false; for (size_t i = 0; i < ncells; i++) { repeat++; - if (i == ncells - 1 || attrs[i] != attrs[i + 1] - || strcmp(chunk[i], chunk[i + 1]) != 0) { + if (i == ncells - 1 || attrs[i] != attrs[i + 1] || chunk[i] != chunk[i + 1]) { if (UI_BUF_SIZE - BUF_POS(data) < 2 * (1 + 2 + sizeof(schar_T) + 5 + 5) + 1) { // close to overflowing the redraw buffer. finish this event, // flush, and start a new "grid_line" event at the current position. @@ -859,7 +858,9 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int uint32_t csize = (repeat > 1) ? 3 : ((attrs[i] != last_hl) ? 2 : 1); nelem++; mpack_array(buf, csize); - mpack_str(buf, chunk[i]); + char sc_buf[MAX_SCHAR_SIZE]; + schar_get(sc_buf, chunk[i]); + mpack_str(buf, sc_buf); if (csize >= 2) { mpack_uint(buf, (uint32_t)attrs[i]); if (csize >= 3) { @@ -869,7 +870,7 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int data->ncells_pending += MIN(repeat, 2); last_hl = attrs[i]; repeat = 0; - was_space = strequal(chunk[i], " "); + was_space = chunk[i] == schar_from_ascii(' '); } } // If the last chunk was all spaces, add a clearing chunk even if there are @@ -893,8 +894,10 @@ void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Int for (int i = 0; i < endcol - startcol; i++) { remote_ui_cursor_goto(ui, row, startcol + i); remote_ui_highlight_set(ui, attrs[i]); - remote_ui_put(ui, chunk[i]); - if (utf_ambiguous_width(utf_ptr2char((char *)chunk[i]))) { + char sc_buf[MAX_SCHAR_SIZE]; + schar_get(sc_buf, chunk[i]); + remote_ui_put(ui, sc_buf); + if (utf_ambiguous_width(utf_ptr2char(sc_buf))) { data->client_col = -1; // force cursor update } } -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/api/ui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 0ea2310042..e0b5e6ea57 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -21,6 +21,7 @@ #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" +#include "nvim/macros.h" #include "nvim/main.h" #include "nvim/map.h" #include "nvim/mbyte.h" -- cgit From 4e6096a67fe9860994be38bcd155e7c47313205e Mon Sep 17 00:00:00 2001 From: George Harker Date: Tue, 31 Oct 2023 20:04:53 -0700 Subject: feat(server): allow embed with listen (#25709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit connection from any channel or stdio will unblock remote_ui_wait_for_attach. Wait on stdio only if only —embed specified, if both —embed and —listen then wait on any channel. --- src/nvim/api/ui.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e0b5e6ea57..b508a3ee94 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -126,18 +126,24 @@ void remote_ui_disconnect(uint64_t channel_id) xfree(ui); } -/// Wait until ui has connected on stdio channel. -void remote_ui_wait_for_attach(void) +/// Wait until ui has connected on stdio channel if only_stdio +/// is true, otherwise any channel. +void remote_ui_wait_for_attach(bool only_stdio) { - Channel *channel = find_channel(CHAN_STDIO); - if (!channel) { - // this function should only be called in --embed mode, stdio channel - // can be assumed. - abort(); - } + if (only_stdio) { + Channel *channel = find_channel(CHAN_STDIO); + if (!channel) { + // this function should only be called in --embed mode, stdio channel + // can be assumed. + abort(); + } - LOOP_PROCESS_EVENTS_UNTIL(&main_loop, channel->events, -1, - map_has(uint64_t, &connected_uis, CHAN_STDIO)); + LOOP_PROCESS_EVENTS_UNTIL(&main_loop, channel->events, -1, + map_has(uint64_t, &connected_uis, CHAN_STDIO)); + } else { + LOOP_PROCESS_EVENTS_UNTIL(&main_loop, main_loop.events, -1, + ui_active()); + } } /// Activates UI events on the channel. -- cgit From 56627ca2423e9d6084f87f5bc4639f06d10ecf91 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:42:40 -0600 Subject: feat(tui): use TermResponse event for OSC responses (#25868) When the terminal emulator sends an OSC sequence to Nvim (as a response to another OSC sequence that was first sent by Nvim), populate the OSC sequence in the v:termresponse variable and fire the TermResponse event. The escape sequence is also included in the "data" field of the autocommand callback when the autocommand is defined in Lua. This makes use of the already documented but unimplemented TermResponse event. This event exists in Vim but is only fired when Vim receives a primary device attributes response. Fixes: https://github.com/neovim/neovim/issues/25856 --- src/nvim/api/ui.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index b508a3ee94..99215f7b4f 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -16,6 +16,7 @@ #include "nvim/api/ui.h" #include "nvim/autocmd.h" #include "nvim/channel.h" +#include "nvim/eval.h" #include "nvim/event/loop.h" #include "nvim/event/wstream.h" #include "nvim/globals.h" @@ -524,6 +525,32 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa ui->pum_pos = true; } +/// Tells Nvim when a terminal event has occurred. +/// +/// The following terminal events are supported: +/// +/// - "osc_response": The terminal sent a OSC response sequence to Nvim. The +/// payload is the received OSC sequence. +/// +/// @param channel_id +/// @param event Event name +/// @param payload Event payload +/// @param[out] err Error details, if any. +void nvim_ui_term_event(uint64_t channel_id, String event, Object value, Error *err) + FUNC_API_SINCE(12) FUNC_API_REMOTE_ONLY +{ + if (strequal("osc_response", event.data)) { + if (value.type != kObjectTypeString) { + api_set_error(err, kErrorTypeValidation, "osc_response must be a string"); + return; + } + + const String osc_response = value.data.string; + set_vim_var_string(VV_TERMRESPONSE, osc_response.data, (ptrdiff_t)osc_response.size); + apply_autocmds_group(EVENT_TERMRESPONSE, NULL, NULL, false, AUGROUP_ALL, NULL, NULL, &value); + } +} + static void flush_event(UIData *data) { if (data->cur_event) { -- cgit From 592e4472da5f29edbddea3eb448e56b747044e67 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:10:45 +0100 Subject: fix(PVS/V564): the '|' operator is applied to bool type value --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 99215f7b4f..d5bb474039 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -77,7 +77,7 @@ static void mpack_uint(char **buf, uint32_t val) static void mpack_bool(char **buf, bool val) { - mpack_w(buf, 0xc2 | val); + mpack_w(buf, 0xc2 | (val ? 1 : 0)); } static void mpack_array(char **buf, uint32_t len) -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/api/ui.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index d5bb474039..3d013435f7 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include -- cgit From ab102f188e86bdbfce1d4de2ef633092a906e8fe Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 6 Nov 2023 15:46:44 -0600 Subject: refactor: move background color detection into Lua --- src/nvim/api/ui.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 3d013435f7..a215317a83 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -348,15 +348,6 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; } - if (strequal(name.data, "term_background")) { - VALIDATE_T("term_background", kObjectTypeString, value.type, { - return; - }); - set_tty_background(value.data.string.data); - ui->term_background = string_to_cstr(value.data.string); - return; - } - if (strequal(name.data, "stdin_fd")) { VALIDATE_T("stdin_fd", kObjectTypeInteger, value.type, { return; -- cgit From 8d9789a0f3b748b75ac4ae1b8e43d27af40d49fe Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 7 Nov 2023 11:31:21 -0600 Subject: docs: deprecate the "term_background" UI field --- src/nvim/api/ui.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index a215317a83..e6d9035b0d 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -120,7 +120,6 @@ void remote_ui_disconnect(uint64_t channel_id) // Destroy `ui`. XFREE_CLEAR(ui->term_name); - XFREE_CLEAR(ui->term_background); xfree(ui); } -- cgit From b73a829837bbc05840ae00cbe514fb1786695614 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Nov 2023 05:15:45 -0800 Subject: refactor: vim.ui.clipboard #26040 Problem: Platform-specific UI providers should live in `vim.ui.*`. #24164 Solution: - Move `vim.clipboard.osc52` module to `vim.ui.clipboard.osc52`. - TODO: move all of `clipboard.vim` to `vim.ui.clipboard`. ref #25872 --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e6d9035b0d..c898925af8 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -512,7 +512,7 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa ui->pum_pos = true; } -/// Tells Nvim when a terminal event has occurred. +/// Tells Nvim when a terminal event has occurred: sets |v:termresponse| and fires |TermResponse|. /// /// The following terminal events are supported: /// -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/api/ui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index c898925af8..1483650739 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include -- cgit From b4b7ca2d548a1cc1a2cd8c48e5c93478811bd275 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Thu, 16 Nov 2023 11:12:42 -0600 Subject: feat(tui): support DCS responses in TermResponse event (#26061) --- src/nvim/api/ui.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 1483650739..c1fc986029 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -513,12 +513,13 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa ui->pum_pos = true; } -/// Tells Nvim when a terminal event has occurred: sets |v:termresponse| and fires |TermResponse|. +/// Tells Nvim when a terminal event has occurred /// /// The following terminal events are supported: /// -/// - "osc_response": The terminal sent a OSC response sequence to Nvim. The -/// payload is the received OSC sequence. +/// - "termresponse": The terminal sent an OSC or DCS response sequence to +/// Nvim. The payload is the received response. Sets +/// |v:termresponse| and fires |TermResponse|. /// /// @param channel_id /// @param event Event name @@ -527,14 +528,14 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa void nvim_ui_term_event(uint64_t channel_id, String event, Object value, Error *err) FUNC_API_SINCE(12) FUNC_API_REMOTE_ONLY { - if (strequal("osc_response", event.data)) { + if (strequal("termresponse", event.data)) { if (value.type != kObjectTypeString) { - api_set_error(err, kErrorTypeValidation, "osc_response must be a string"); + api_set_error(err, kErrorTypeValidation, "termresponse must be a string"); return; } - const String osc_response = value.data.string; - set_vim_var_string(VV_TERMRESPONSE, osc_response.data, (ptrdiff_t)osc_response.size); + const String termresponse = value.data.string; + set_vim_var_string(VV_TERMRESPONSE, termresponse.data, (ptrdiff_t)termresponse.size); apply_autocmds_group(EVENT_TERMRESPONSE, NULL, NULL, false, AUGROUP_ALL, NULL, NULL, &value); } } -- cgit From 09541d514dd18bf86f673d3784d406236fcbdad8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 09:51:26 +0800 Subject: build(IWYU): replace public-to-public mappings with pragmas (#26237) --- src/nvim/api/ui.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index c1fc986029..52165420b2 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -26,7 +26,6 @@ #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/option.h" #include "nvim/types.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/api/ui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 52165420b2..7366e24703 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -17,6 +17,7 @@ #include "nvim/eval.h" #include "nvim/event/loop.h" #include "nvim/event/wstream.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/api/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 7366e24703..9eb1cc675f 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -29,7 +29,7 @@ #include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/option.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/api/ui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 9eb1cc675f..bf554a8829 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -21,9 +21,9 @@ #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/main.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" @@ -31,7 +31,7 @@ #include "nvim/option.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #define BUF_POS(data) ((size_t)((data)->buf_wptr - (data)->buf)) -- cgit From 86cc791debba09c8ed1aa0d863be844108866a38 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 23:10:21 +0800 Subject: refactor: move function macros out of vim_defs.h (#26300) --- src/nvim/api/ui.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index bf554a8829..836a68546c 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -31,7 +31,6 @@ #include "nvim/option.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim_defs.h" #define BUF_POS(data) ((size_t)((data)->buf_wptr - (data)->buf)) -- cgit