From ff75f345ab5fa57c6560db021e8eb099aff90472 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Nov 2024 06:52:32 +0800 Subject: fix(highlight): 'winhl' shouldn't take priority over API (#31288) --- src/nvim/api/window.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 5a4972ef23..ee7729ce81 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -476,6 +476,7 @@ void nvim_win_set_hl_ns(Window window, Integer ns_id, Error *err) } win->w_ns_hl = (NS)ns_id; + win->w_ns_hl_winhl = -1; win->w_hl_needs_update = true; redraw_later(win, UPD_NOT_VALID); } -- cgit From 01a97d2ad75a459cad850d542f9ad7c4467cb380 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:59:24 +0800 Subject: fix(api): nvim_win_set_buf(0, 0) fails if 'winfixbuf' is set #31576 ## Problem With 'winfixbuf' enabled, `nvim_win_set_buf` and `nvim_set_current_buf` fail even if targeting the already-current buffer. vim.wo.winfixbuf = true vim.api.nvim_win_set_buf(0, 0) vim.api.nvim_set_current_buf(0) Solution: Check for this condition. --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index ee7729ce81..f415415fa7 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -59,7 +59,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) { win_T *win = find_window_by_handle(window, err); buf_T *buf = find_buffer_by_handle(buffer, err); - if (!win || !buf) { + if (!win || !buf || win->w_buffer == buf) { return; } -- cgit From 167a2383b9966ac227a77b0221088246e14ce75a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 16 Dec 2024 04:00:20 -0800 Subject: fix(api): not using TRY_WRAP, generic error messages #31595 Problem: - API functions using `try_start` directly instead of `TRY_WRAP`, do not surface the underlying error message, and instead show generic things like "Failed to set buffer". - Error handling code is duplicated in the API impl, instead of delegating to the vim buffer/window handling logic. Solution: - Use `TRY_WRAP`. --- src/nvim/api/window.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f415415fa7..170d5c6cdb 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -59,12 +59,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) { win_T *win = find_window_by_handle(window, err); buf_T *buf = find_buffer_by_handle(buffer, err); - if (!win || !buf || win->w_buffer == buf) { - return; - } - - if (win->w_p_wfb) { - api_set_error(err, kErrorTypeException, "%s", e_winfixbuf_cannot_go_to_buffer); + if (!win || !buf) { return; } -- cgit From 022449b5223659d515b78bada7de2fac8718820a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 16 Dec 2024 08:34:16 -0800 Subject: fix(api): generic error messages, not using TRY_WRAP #31596 Problem: - API functions using `try_start` directly, do not surface the underlying error message, and instead show generic messages. - Error-handling code is duplicated in the API impl. - Failure modes are not tested. Solution: - Use `TRY_WRAP`. - Add tests. --- src/nvim/api/window.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 170d5c6cdb..f5e8d8f086 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -182,14 +182,9 @@ void nvim_win_set_height(Window window, Integer height, Error *err) return; } - if (height > INT_MAX || height < INT_MIN) { - api_set_error(err, kErrorTypeValidation, "Height value outside range"); - return; - } - - try_start(); - win_setheight_win((int)height, win); - try_end(err); + TRY_WRAP(err, { + win_setheight_win((int)height, win); + }); } /// Gets the window width @@ -224,14 +219,9 @@ void nvim_win_set_width(Window window, Integer width, Error *err) return; } - if (width > INT_MAX || width < INT_MIN) { - api_set_error(err, kErrorTypeValidation, "Width value outside range"); - return; - } - - try_start(); - win_setwidth_win((int)width, win); - try_end(err); + TRY_WRAP(err, { + win_setwidth_win((int)width, win); + }); } /// Gets a window-scoped (w:) variable @@ -436,15 +426,15 @@ Object nvim_win_call(Window window, LuaRef fun, Error *err) } tabpage_T *tabpage = win_find_tabpage(win); - try_start(); Object res = OBJECT_INIT; - win_execute_T win_execute_args; - if (win_execute_before(&win_execute_args, win, tabpage)) { - Array args = ARRAY_DICT_INIT; - res = nlua_call_ref(fun, NULL, args, kRetLuaref, NULL, err); - } - win_execute_after(&win_execute_args); - try_end(err); + TRY_WRAP(err, { + win_execute_T win_execute_args; + if (win_execute_before(&win_execute_args, win, tabpage)) { + Array args = ARRAY_DICT_INIT; + res = nlua_call_ref(fun, NULL, args, kRetLuaref, NULL, err); + } + win_execute_after(&win_execute_args); + }); return res; } -- cgit From 6bf2a6fc5bb395b67c88cb26d332f882a106c7ab Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Tue, 17 Dec 2024 13:12:22 +0100 Subject: refactor(api): always use TRY_WRAP #31600 Problem: Two separate try/end wrappers, that only marginally differ by restoring a few variables. Wrappers that don't restore previous state are dangerous to use in "api-fast" functions. Solution: Remove wrappers that don't restore the previous state. Always use TRY_WRAP. --- src/nvim/api/window.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f5e8d8f086..387dad899e 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -368,19 +368,16 @@ void nvim_win_hide(Window window, Error *err) } tabpage_T *tabpage = win_find_tabpage(win); - TryState tstate; - try_enter(&tstate); - - // Never close the autocommand window. - if (is_aucmd_win(win)) { - emsg(_(e_autocmd_close)); - } else if (tabpage == curtab) { - win_close(win, false, false); - } else { - win_close_othertab(win, false, tabpage); - } - - vim_ignored = try_leave(&tstate, err); + TRY_WRAP(err, { + // Never close the autocommand window. + if (is_aucmd_win(win)) { + emsg(_(e_autocmd_close)); + } else if (tabpage == curtab) { + win_close(win, false, false); + } else { + win_close_othertab(win, false, tabpage); + } + }); } /// Closes the window (like |:close| with a |window-ID|). @@ -400,10 +397,9 @@ void nvim_win_close(Window window, Boolean force, Error *err) } tabpage_T *tabpage = win_find_tabpage(win); - TryState tstate; - try_enter(&tstate); - ex_win_close(force, win, tabpage == curtab ? NULL : tabpage); - vim_ignored = try_leave(&tstate, err); + TRY_WRAP(err, { + ex_win_close(force, win, tabpage == curtab ? NULL : tabpage); + }); } /// Calls a function with window as temporary current window. -- cgit From 2a7d0ed6145bf3f8b139c2694563f460f829813a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 Dec 2024 05:43:52 -0800 Subject: refactor: iwyu #31637 Result of `make iwyu` (after some "fixups"). --- src/nvim/api/window.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 387dad899e..d968af421d 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -28,7 +27,7 @@ #include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "api/window.c.generated.h" +# include "api/window.c.generated.h" // IWYU pragma: keep #endif /// Gets the current buffer in a window -- cgit