From 69bb145cea56067e6e82ed0a130a51c0d611e540 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Feb 2023 20:14:31 +0800 Subject: refactor(exit): pass error message to preserve_exit() (#22097) Problem: 1. Some calls to preserve_exit() don't put a message in IObuff, so the IObuff printed by preserve_exit() contains unrelated information. 2. If a TUI client runs out of memory or receives a deadly signal, the error message is shown on alternate screen and cannot be easily seen because the TUI exits alternate screen soon afterwards. Solution: Pass error message to preserve_exit() and exit alternate screen before printing it. Note that this doesn't fix the problem that server error messages cannot be easily seen on exit. This is tracked in #21608 and #21843. --- src/nvim/ui_client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index b5c8dff412..58edd7aff3 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -122,7 +122,9 @@ void ui_client_run(bool remote_ui) void ui_client_stop(void) { - tui_stop(tui); + if (!tui_is_stopped(tui)) { + tui_stop(tui); + } } void ui_client_set_size(int width, int height) -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/ui_client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 58edd7aff3..a7a85bf61f 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -22,6 +22,10 @@ #include "nvim/ui.h" #include "nvim/ui_client.h" +#ifdef MSWIN +# include "nvim/os/os_win_console.h" +#endif + static TUIData *tui = NULL; static bool ui_client_is_remote = false; @@ -31,7 +35,6 @@ static bool ui_client_is_remote = false; # include "ui_events_client.generated.h" #endif // uncrustify:on -// uint64_t ui_client_start_server(int argc, char **argv) { -- cgit From 820430dc0bb84011edae801262e64a10be7ebb9d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Feb 2023 16:33:20 +0800 Subject: fix(tui): exit on input eof --- 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 a7a85bf61f..df0a26c6ee 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -113,7 +113,7 @@ void ui_client_run(bool remote_ui) ui_client_is_remote = remote_ui; int width, height; char *term; - tui = tui_start(&width, &height, &term); + tui_start(&tui, &width, &height, &term); ui_client_attach(width, height, term); -- cgit From 371a74e4e1685f21e83c70eb8f0bd05c2ce24e49 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Feb 2023 11:19:40 +0800 Subject: fix(tui): only forward stdin_fd on first attach (#22293) --- src/nvim/ui_client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index df0a26c6ee..0bd9490368 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -93,6 +93,7 @@ void ui_client_attach(int width, int height, char *term) PUT_C(opts, "stdout_tty", BOOLEAN_OBJ(stdout_isatty)); if (ui_client_forward_stdin) { PUT_C(opts, "stdin_fd", INTEGER_OBJ(UI_CLIENT_STDIN_FD)); + ui_client_forward_stdin = false; // stdin shouldn't be forwarded again #22292 } } ADD_C(args, DICTIONARY_OBJ(opts)); -- 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/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 0bd9490368..8262293ec5 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -153,7 +153,7 @@ UIClientHandler ui_client_get_redraw_handler(const char *name, size_t name_len, /// Placeholder for _sync_ requests with 'redraw' method name /// -/// async 'redraw' events, which are expected when nvim acts as an ui client. +/// async 'redraw' events, which are expected when nvim acts as a ui client. /// get handled in msgpack_rpc/unpacker.c and directly dispatched to handlers /// of specific ui events, like ui_client_event_grid_resize and so on. Object handle_ui_client_redraw(uint64_t channel_id, Array args, Arena *arena, Error *error) -- 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/ui_client.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 8262293ec5..25ff63ea2d 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -1,6 +1,8 @@ // 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 +/// Nvim's own UI client, which attaches to a child or remote Nvim server. + #include #include #include -- 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/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 25ff63ea2d..b93b31f7dc 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -43,7 +43,7 @@ uint64_t ui_client_start_server(int argc, char **argv) varnumber_T exit_status; char **args = xmalloc(((size_t)(2 + argc)) * sizeof(char *)); int args_idx = 0; - args[args_idx++] = xstrdup((const char *)get_vim_var_str(VV_PROGPATH)); + args[args_idx++] = xstrdup(get_vim_var_str(VV_PROGPATH)); args[args_idx++] = xstrdup("--embed"); for (int i = 1; i < argc; i++) { args[args_idx++] = xstrdup(argv[i]); -- cgit From 4d654472e65ed28b7cd9e66c91d98b9991452266 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 21 Apr 2023 11:30:31 +0200 Subject: fix(ui_client): check return code of dup() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gsrc/nvim/ui_client.c: In function ‘ui_client_start_server’: gsrc/nvim/ui_client.c:68:5: warning: ignoring return value of ‘dup’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 68 | dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/nvim/ui_client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index b93b31f7dc..e177c0a60d 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -65,7 +65,11 @@ uint64_t ui_client_start_server(int argc, char **argv) #ifdef MSWIN os_open_conin_fd(); #else - dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO); + int fd = dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO); + if (fd < 0) { + return 0; + } + // FIXME: resource leak of fd #endif } -- cgit From 936b78e811a4264c914dbc4753f591b8a3a0f7ff Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 21 Apr 2023 17:50:37 +0200 Subject: refactor: revert incorrect change to ui_client.c code - There is no "resource leak". - "return 0" is definitely not the correct behavior if we ever occur a platform where this would fail. - There was no problem here to fix. so let's not "fix" it. - once CI is upgraded to gcc 13, we'll figure out the correct way to make it shut the fuck up. warnings on non-ci platforms are not critical. --- src/nvim/ui_client.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index e177c0a60d..b93b31f7dc 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -65,11 +65,7 @@ uint64_t ui_client_start_server(int argc, char **argv) #ifdef MSWIN os_open_conin_fd(); #else - int fd = dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO); - if (fd < 0) { - return 0; - } - // FIXME: resource leak of fd + dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO); #endif } -- 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/ui_client.c | 4 ++-- 1 file changed, 2 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 b93b31f7dc..1918b0b800 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -83,11 +83,11 @@ void ui_client_attach(int width, int height, char *term) PUT_C(opts, "ext_linegrid", BOOLEAN_OBJ(true)); PUT_C(opts, "ext_termcolors", BOOLEAN_OBJ(true)); if (term) { - PUT_C(opts, "term_name", STRING_OBJ(cstr_as_string(term))); + PUT_C(opts, "term_name", CSTR_AS_OBJ(term)); } if (ui_client_bg_response != kNone) { bool is_dark = (ui_client_bg_response == kTrue); - PUT_C(opts, "term_background", STRING_OBJ(cstr_as_string(is_dark ? "dark" : "light"))); + PUT_C(opts, "term_background", CSTR_AS_OBJ(is_dark ? "dark" : "light")); } PUT_C(opts, "term_colors", INTEGER_OBJ(t_colors)); if (!ui_client_is_remote) { -- 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/ui_client.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 1918b0b800..9395ff2f1e 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -210,9 +210,7 @@ void ui_client_event_raw_line(GridLineEvent *g) int grid = g->args[0], row = g->args[1], startcol = g->args[2]; Integer endcol = startcol + g->coloff; Integer clearcol = endcol + g->clear_width; - - // TODO(hlpr98): Accommodate other LineFlags when included in grid_line - LineFlags lineflags = 0; + LineFlags lineflags = g->wrap ? kLineFlagWrap : 0; tui_raw_line(tui, grid, row, startcol, endcol, clearcol, g->cur_attr, lineflags, (const schar_T *)grid_line_buf_char, grid_line_buf_attr); -- cgit From 0ce065a332cbd3874bd68a86fa9eda20c5467170 Mon Sep 17 00:00:00 2001 From: t0muxx <30345035+t0muxx@users.noreply.github.com> Date: Wed, 14 Jun 2023 09:39:14 +0000 Subject: fix(tui): v:argv does not report the original argv[0] #24015 Problem: Since TUI was moved to another process 24488169564c39a506c235bf6a33b8e23a8cb528 v:argv and v:progname don't report the original argv[0]. ["/usr/bin/nvim", "--embed", ...] Solution: Use argv[0] instead of VV_PROGPATH in ui_client_start_server(). Fix #23953 --- 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 1918b0b800..cd5c655cc0 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -43,7 +43,7 @@ uint64_t ui_client_start_server(int argc, char **argv) varnumber_T exit_status; char **args = xmalloc(((size_t)(2 + argc)) * sizeof(char *)); int args_idx = 0; - args[args_idx++] = xstrdup(get_vim_var_str(VV_PROGPATH)); + args[args_idx++] = xstrdup(argv[0]); args[args_idx++] = xstrdup("--embed"); for (int i = 1; i < argc; i++) { args[args_idx++] = xstrdup(argv[i]); -- cgit From 559c4cfd52e385c1b9bd5fa66a0eeb7e8d9e018a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Jul 2023 08:27:39 +0800 Subject: fix(startup): run embedded Nvim with real path (#24282) fix(startup): run embedded process with real path --- src/nvim/ui_client.c | 4 ++-- 1 file changed, 2 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 0fc6d4936d..cc564f4777 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -53,8 +53,8 @@ uint64_t ui_client_start_server(int argc, char **argv) CallbackReader on_err = CALLBACK_READER_INIT; on_err.fwd_err = true; - Channel *channel = channel_job_start(args, CALLBACK_READER_INIT, - on_err, CALLBACK_NONE, + Channel *channel = channel_job_start(args, get_vim_var_str(VV_PROGPATH), + CALLBACK_READER_INIT, on_err, CALLBACK_NONE, false, true, true, false, kChannelStdinPipe, NULL, 0, 0, NULL, &exit_status); -- 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/ui_client.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index cc564f4777..8e60af478b 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -7,6 +7,8 @@ #include #include +#include "nvim/api/keysets.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/channel.h" #include "nvim/eval.h" -- 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/ui_client.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 8e60af478b..dac690822b 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.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 - /// Nvim's own UI client, which attaches to a child or remote Nvim server. #include -- 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/ui_client.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index dac690822b..2f91257a5d 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -84,10 +84,7 @@ void ui_client_attach(int width, int height, char *term) if (term) { PUT_C(opts, "term_name", CSTR_AS_OBJ(term)); } - if (ui_client_bg_response != kNone) { - bool is_dark = (ui_client_bg_response == kTrue); - PUT_C(opts, "term_background", CSTR_AS_OBJ(is_dark ? "dark" : "light")); - } + PUT_C(opts, "term_colors", INTEGER_OBJ(t_colors)); if (!ui_client_is_remote) { PUT_C(opts, "stdin_tty", BOOLEAN_OBJ(stdin_isatty)); -- 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/ui_client.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 2f91257a5d..13756ace3c 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -17,7 +17,6 @@ #include "nvim/main.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/os/os_defs.h" #include "nvim/tui/tui.h" #include "nvim/ui.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/ui_client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ui_client.c') diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 13756ace3c..3012d6fbee 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -11,6 +11,7 @@ #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" #include "nvim/event/loop.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/log.h" -- cgit From e3f735ef101d670555f44226614a5c3557053b1f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:13:32 +0100 Subject: refactor: fix includes for api/autocmd.h --- 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 3012d6fbee..30f44d182d 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -4,7 +4,7 @@ #include #include -#include "nvim/api/keysets.h" +#include "nvim/api/keysets_defs.h" #include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/channel.h" -- cgit