echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
5.29k stars 190 forks source link

mini.starter: stackoverflow when #items=1 and evaluate_single=true #718

Closed abeldekat closed 7 months ago

abeldekat commented 8 months ago

Contributing guidelines

Module(s)

mini.starter

Description

I replaced dashboard-nvim with mini.starter, adding items one by one. When there is only one item in items, and evaluate_single=true, a stackoverflow occurs.

I think that the culprit is in this fragment

Neovim version

0.9.5

Steps to reproduce

local function bootstrap(root)
  for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
  end

  local packpath = root .. "/data/nvim/site"
  local minipath = packpath .. "/pack/deps/start/mini.nvim"
  if not vim.loop.fs_stat(minipath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/echasnovski/mini.nvim.git", minipath })
  end

  vim.cmd("set packpath=" .. packpath)
  vim.cmd.packadd("mini.nvim")
end
local root = vim.fn.fnamemodify("./.repro", ":p")
bootstrap(root)

vim.o.background = "dark"
require("mini.hues").setup({ background = "#11262d", foreground = "#c0c8cc" })

require("mini.starter").setup({
  evaluate_single = true,
  items = {
    { action = 'echo "hello"', name = "hello", section = "default" },
    -- { action = 'echo "goodbye"', name = "goodbye", section = "default" },
  },
})

Expected behavior

...

Actual behavior

Error detected while processing UIEnter Autocommands for "*":
Error executing lua callback: stack overflow
stack traceback:
        [C]: in function 'insert'
        vim/_editor.lua: in function 'region'
        /usr/share/nvim/runtime/lua/vim/highlight.lua:35: in function 'range'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1520: in function 'buf_hl'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1413: in function 'add_hl_activity'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1292: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:897: in function 'eval_current_item'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1296: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:897: in function 'eval_current_item'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1296: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:897: in function 'eval_current_item'
        ...
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1296: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:897: in function 'eval_current_item'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1296: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:897: in function 'eval_current_item'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1296: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:897: in function 'eval_current_item'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:1296: in function 'make_query'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:393: in function 'refresh'
        ...nvim/site/pack/deps/start/mini.nvim/lua/mini/starter.lua:311: in function 'open'
        /home/user/.config/nvim/lua/ak/config/ui/mini_starter.lua:14: in function </home/user/.config/nvim/lua/ak/config/ui/mini_starter.lua:12>
echasnovski commented 8 months ago

Thanks for the issue!

This is somewhat expected, though:

I'll take a look if there is a reasonable approach to mitigate this.

echasnovski commented 7 months ago

After thinking more about this, I think this is an OK behavior. Mostly because it is somewhat expected (as described before). But also resolving this might contradict the design of allowing items to be evaluated several times in a single Starter buffer (like "narrow down" -> "evaluate" -> "narrow down" -> "evaluate" kind of loop).

Closing as "please don't create single entry items along with evaluate_single = true".

abeldekat commented 7 months ago

Closing as "please don't create single entry items along with evaluate_single = true".

This had me smile. I promise I won't do this ever again....)

mg979 commented 5 months ago

Just had the same problem. In sections like recent files (current directory only) you can't know how many items there will be. This means evaluate_single = true can't be used safely.

echasnovski commented 5 months ago

Just had the same problem. In sections like recent files (current directory only) you can't know how many items there will be. This means evaluate_single = true can't be used safely.

I think this might be the problem only on new-ish installation (or directory if latest files are configured to use only current directory) and if there is only one section. It seems like a reasonably rare and solvable (add section with "edit" and "quit" items, for example) issue.