VoxelPrismatic / rabbit.nvim

Quickly jump between buffers
56 stars 0 forks source link

bad argument #2 to 'min' (number expected, got nil) #6

Closed jeromepin closed 4 months ago

jeromepin commented 4 months ago

Hey !

I hoped to try out Rabbit but cannot run it now.

I get the following stack trace because it cannot get a value from https://github.com/VoxelPrismatic/rabbit.nvim/blob/v3.1.4/lua/rabbit/init.lua#L263

Error executing Lua callback: ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:268: bad argument #2 to 'min' (number expected, got nil)
stack traceback:
        [C]: in function 'min'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:268: in function 'MakeBuf'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:350: in function 'Window'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:488: in function 'Switch'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:556: in function <...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:556>

I'm on MacOS 14.4.1 with neovim v0.9.4 and Rabbit v3.1.5 (74c1028)

VoxelPrismatic commented 4 months ago

Can I see your config? Specifically the window options

jeromepin commented 4 months ago

Ah yes, my bad, I forgot to add that part...

I tried with both an empty block :

{
        'VoxelPrismatic/rabbit.nvim',
        version = 'v3.1.*',
        config = function()
            require("rabbit").setup({})
        end
}
And the default configuration shown in the README (and copy-pasted) ```lua { colors = { title = { -- Title text fg = "#000000", -- Grabs from :hi Normal bold = true, }, index = { -- Index numbers fg = "#000000", -- Grabs from :hi Comment italic = true, }, dir = "#000000", -- Folders; Grabs from :hi NonText file = "#000000", -- File name; Grabs from :hi Normal term = { -- Addons, eg :term or :Oil fg = "#000000", -- Grabs from :hi Constant italic = true, }, noname = { -- No buffer name set fg = "#000000", -- Grabs from :hi Function italic = true, }, message = { fg = "#000000", -- Grabs from :hi Identifier italic = true, }, }, window = { -- If `box_style` is specified, it will overwrite anything set in `box` box_style = "round", -- One of "round", "square", "thick", "double" box = { top_left = "╭", -- Top left corner of box top_right = "╮", -- Top right corner of box bottom_left = "╰", -- Bottom left corner of box bottom_right = "╯", -- Bottom right corner of box vertical = "│", -- Vertical wall horizontal = "─", -- Horizontal ceiling emphasis = "═", -- Emphasis around title, like `──══ Rabbit ══──` }, width = 64, -- Width, in columns height = 24, -- Height, in rows -- Where the plugin name should be displayed. -- * "bottom" means in the bottom left corner, but not displayed in full screen -- * "title" means next to rabbit, eg `──══ Rabbit History ══──` -- * "hide" means to not display it at all plugin_name_position = "bottom", title = "Rabbit", -- Title text, eg: `──══ Rabbit ══──` or `──══ NotHarpoon ══──` emphasis_width = 8, -- Eg: `──────══ Rabbit ══──────` or `──══════ Rabbit ══════──` float = true, -- Plain `true` means use bottom right corner float = "center", -- Aligns to center float = { top = 10000, -- Top offset in lines left = 10000, -- Left offset in columns }, float = { "bottom", -- "top" or "bottom;" MUST BE FIRST "right", -- "left" or "right;" MUST BE LAST }, -- When using split screen, it will try to use the width and height provided earlier. -- Eg, when splitting left or right: height = 100%; width = `width` -- Eg, when splitting above or below: height = `height`; width = 100% -- NOTE: `float` must be explicitly set to false in order to split -- NOTE: If both `float` and `split` are false, a new buffer will open, "fullscreen" split = true, -- Plain `true` means use the right side split = "right", -- One of "left", "right", "above", "below" overflow = ":::", -- String to display when folders overflow path_len = 12, -- How many characters to display in folder name before cutting off }, default_keys = { close = { -- Default bindings to close Rabbit "", "q", "", }, select = { -- Default bindings to select a buffer "", }, open = { -- Default bindings to open Rabbit "r", }, file_add = { -- Default bindings to add current buffer to persistent history "a", -- This would act like Prime's Harpoon, but it isn't implemented yet }, file_del = { -- Default bindings to remove current buffer from persistent history "d", -- This would act like Prime's Harpoon, but it isn't implemented yet }, }, plugin_opts = { -- Plugin specific options you'd like to set history = { color = "#d7827e", -- Border color switch = "r", -- Keybind to switch to the history window from within Rabbit keys = {}, -- See the API for more details opts = {}, -- See the API for more details }, reopen = { color = "#907aa9", -- Border color switch = "o", -- Keybind to switch to the reopen window from within Rabbit keys = {}, -- See the API for more details opts = {}, -- See the API for more details }, }, enable = { -- Builtin plugins to enable immediately "history", -- The plugin shown when opening Rabbit "reopen", "oxide", }, } ```

Both shown the same issue.

I'm running :Rabbit history on two already opened buffers.

And :lua =vim.api.nvim_get_current_win() returns 1000 👍

VoxelPrismatic commented 4 months ago

Can you try the new 3.2.0 update? I'm sure it solves it, unless somehow the width of your window is nil

jeromepin commented 4 months ago

On ad5f0c5, it still doesn't work with the same error, sorry.

VoxelPrismatic commented 4 months ago

what is returned by this?

:lua vim.print(vim.api.nvim_win_get_config(0))
jeromepin commented 4 months ago

I get

{
  external = false,
  focusable = true,
  relative = ""
}

So height (or width) isn't set :(

VoxelPrismatic commented 4 months ago

fascinating

VoxelPrismatic commented 4 months ago

For when I get back home: Line 253:

local win_conf = vim.api.nvim_win_get_config(rabbit.user.win)
if win_conf.width == nil or win_conf.height == nil then
    win_conf.width = vim.api.nvim_win_get_width(rabbit.user.win)
    win_conf.height = vim.api.nvim_win_get_height(rabbit.user.win)
end
jeromepin commented 4 months ago

So I modified my local copy (on ad5f0c5) of Rabbit with what you typed for yourself :

diff --git i/lua/rabbit/init.lua w/lua/rabbit/init.lua
index eb5d3e9..d6a1245 100644
--- i/lua/rabbit/init.lua
+++ w/lua/rabbit/init.lua
@@ -251,6 +251,10 @@ function rabbit.MakeBuf(mode)
 -- Create buffer
     local buf = vim.api.nvim_create_buf(false, true)
     local win_conf = vim.api.nvim_win_get_config(rabbit.user.win)
+    if win_conf.width == nil or win_conf.height == nil then
+        win_conf.width = vim.api.nvim_win_get_width(rabbit.user.win)
+        win_conf.height = vim.api.nvim_win_get_height(rabbit.user.win)
+    end
     rabbit.rabbit.buf = buf

 -- Generate configuration
Details `nvim_win_get_width` and `nvim_win_get_height` returns respectively `238` and `55` so it's working !

But I get another issue then 😅

The Rabbit popup shows (at the bottom right corner) but says "There's nowhere to jump to! Get started by opening another buffer" while I have two buffers opened :

:buffers
  1 #a   "cell.py"                      line 1
  2      "~/git/github/lumapps/infra/Makefile" line 0

Then the stacktrace appears :

E5108: Error executing lua: ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:155: BufLeave Autocommands for "<buffer=4>": Vim(append):Error executing lua callback: ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:156
: attempt to call field 'nvim_tabpage_set_win' (a nil value)
stack traceback:
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:156: in function <...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:150>
        [C]: in function 'nvim_win_close'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:155: in function 'close'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:177: in function 'cb'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:504: in function <...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:504>
stack traceback:
        [C]: in function 'nvim_win_close'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:155: in function 'close'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:177: in function 'cb'
        ...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:504: in function <...n/.local/share/nvim/lazy/rabbit.nvim/lua/rabbit/init.lua:504>

Sorry for all the disturbance 😅 I can stop using Rabbit if you prefer 🙇

VoxelPrismatic commented 4 months ago

Line 155:

            -- For split windows; returns to expected window
            vim.api.nvim_set_current_win(rabbit.user.win)

tabpage_set_win(0, rabbit.user.win) seems to be redundant

jeromepin commented 4 months ago

Indeed ! It's working properly if I remove the tabpage_set_win line.

About the There's nowhere to jump to! Get started by opening another buffer message, it's because while I had multiple buffers opened, I had visited only the first one. Therefore, Rabbit history didn't have any "visited buffer history" to show.

Thank you very much for your time @VoxelPrismatic 🙏