From b4229a094bdebe82d6f0b9aa69fea23a9e4b6b61 Mon Sep 17 00:00:00 2001 From: Anthony <89563512+bezlant@users.noreply.github.com> Date: Mon, 21 Jul 2025 19:27:19 +0800 Subject: [PATCH] fix: plenary usage crash (#156) Fixes bug created in the [commit ac4a400](https://github.com/kdheepak/lazygit.nvim/commit/ac4a400b256a63ae9d533b022db9b98d3358ef55) **Prevent crash when using plenary.window.float for floating window** This MR fixes a bug caused by inconsistent return values from get_window_pos() when vim.g.lazygit_floating_window_use_plenary is enabled. **Problem** When plenary.window.float is used, get_window_pos() returned (win_id, bufnr) instead of the expected (width, height, row, col). This led to a runtime error: E5108: Error executing lua ...window.lua:33: attempt to perform arithmetic on local 'row' (a nil value) **Solution** Ensure that get_window_pos() always returns consistent values and explicitly handle the Plenary case in open_floating_window(). This prevents arithmetic operations on nil values and restores compatibility with the Plenary-based layout logic. **Tested** - Works correctly with and without vim.g.lazygit_floating_window_use_plenary set. - No runtime errors on window resize or open. - Borders and buffer correctly positioned in both modes. Co-authored-by: abezlyudniy --- lua/lazygit/window.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/lazygit/window.lua b/lua/lazygit/window.lua index 21a4d04..32fb1c9 100644 --- a/lua/lazygit/window.lua +++ b/lua/lazygit/window.lua @@ -11,9 +11,12 @@ local function get_window_pos() local status, plenary = pcall(require, 'plenary.window.float') if status and vim.g.lazygit_floating_window_use_plenary and vim.g.lazygit_floating_window_use_plenary ~= 0 then - local ret = plenary.percentage_range_window(floating_window_scaling_factor, floating_window_scaling_factor, - { winblend = vim.g.lazygit_floating_window_winblend }) - return ret.win_id, ret.bufnr + local ret = plenary.percentage_range_window( + floating_window_scaling_factor, + floating_window_scaling_factor, + { winblend = vim.g.lazygit_floating_window_winblend } + ) + return nil, nil, nil, nil, ret.win_id, ret.bufnr end local height = math.ceil(vim.o.lines * floating_window_scaling_factor) - 1 @@ -25,7 +28,10 @@ end --- open floating window with nice borders local function open_floating_window() - local width, height, row, col = get_window_pos() + local width, height, row, col, plenary_win, plenary_buf = get_window_pos() + if plenary_win and plenary_buf then + return plenary_win, plenary_buf + end local border_opts = { style = 'minimal',