snacks.nvim icon indicating copy to clipboard operation
snacks.nvim copied to clipboard

bug: empty lazy picker

Open tnxz opened this issue 1 month ago • 6 comments

Did you check docs and existing issues?

  • [x] I have read all the snacks.nvim docs
  • [x] I have updated the plugin to the latest version before submitting this issue
  • [x] I have searched the existing issues of snacks.nvim
  • [x] I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

v0.12.0-dev-1651+g4998b8d7b5

Operating system/version

macOS 26.0.1

Describe the bug

:lua Snacks.picker.lazy()<cr>

No results found for lazy

Steps To Reproduce

run :lua Snacks.picker.lazy()

Expected Behavior

open plugin spec in filepicker

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/snacks.nvim", opts = {} },
    -- add any other plugins here
  },
})

tnxz avatar Nov 20 '25 10:11 tnxz

I’ll try to translate it.

He uses a single-file configuration in init.lua, meaning all his plugins are defined inside that file. Snacks.picker.lazy() skips all plugins declared in the init file.

https://github.com/folke/snacks.nvim/blob/fe7cfe9800a182274d0f868a74b7263b8c0c020b/lua/snacks/picker/source/lazy.lua#L7

  local paths = { vim.fn.stdpath("config") .. "/init.lua" } ---@type string[]

drowning-cat avatar Nov 20 '25 16:11 drowning-cat

That's because the picker only supports imports and then it searches those directories files and parses the lines of each file to find the plugins names.

Based on my basic knowledge it would be difficult to support this kind of setup as OP. The reason is because the file could not always be init.lua. Take LazyVim for example. A user could just add his entire plugin configuration here. I've seen other setups as well, where init.lua just requires the module where lazy.nvim is being setup and called. That is currently not stored anywhere by lazy.nvim if I'm not mistaken.

You could maybe provide support for basic plugin names by getting the information from require("lazy.core.config").spec.plugins, but that would then not be able to provide the item's location in the file, as the picker currently does for items from imports.

So, without a proper mechanism to find the file that lazy.nvim is setup (which would probably require some changes in lazy.nvim codebase and I'm not sure if Folke would want to go to such lengths), I believe this is difficult to support.

Of course that is just my basic knowledge and I could be wrong, but that's my understanding with regards to this situation.

dpetka2001 avatar Nov 20 '25 19:11 dpetka2001

What does that jave to do with where lazy.nvim is setup? Didn't you read my comment? It might not always be init.lua, because init.lua might just require the module where lazy.nvim is actually setup. So init.lua might just have something like require("config.lazy") or some other module. Some ppl even still use .vimrc and have the lazy setup there.

dpetka2001 avatar Nov 20 '25 21:11 dpetka2001

I did read your message, and I didn’t say you were wrong. This code isn’t meant to be a solution. It is more of an explanation, if you will. Sorry, it might be confusing in this context, so I moved it :0

drowning-cat avatar Nov 20 '25 21:11 drowning-cat

Sorry i did not mean to be rude. But the thing that is troubling, is that currently there's no way to determine from which file lazy.nvim will be setup. It could be any file and not necessarily just init.lua. So, it's not that easy as just adding init.lua to the paths table.

But that's only what i can gather from my quick search through Lazy's codebase and that was a long time ago and of course i might have missed something.

I believe further changes would need to be made in Lazy (if that is possible, which i don't know for sure) and that is up to Folke to decide. Or maybe there's a way to do what OP wants and i'm just not aware of it.

But with the current implementation of Snacks lazy picker, this is just not supported i believe.

dpetka2001 avatar Nov 20 '25 21:11 dpetka2001

@drowning-cat

With this patch for Lazy

diff --git a/lua/lazy/init.lua b/lua/lazy/init.lua
index 4336da1..1baaeea 100644
--- a/lua/lazy/init.lua
+++ b/lua/lazy/init.lua
@@ -29,6 +29,8 @@ end
 ---@overload fun(opts: LazyConfig)
 ---@overload fun(spec:LazySpec, opts: LazyConfig)
 function M.setup(spec, opts)
+  local info = debug.getinfo(2, "S")
+  local caller_loc = info.short_src
   if type(spec) == "table" and spec.spec then
     ---@cast spec LazyConfig
     opts = spec
@@ -105,7 +107,7 @@ function M.setup(spec, opts)
   local delta = vim.uv.hrtime() - start
   Util.track().time = delta -- end setup
   if Config.plugins["lazy.nvim"] then
-    Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua" }
+    Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua", location = caller_loc }
   end
 
   -- load plugins with lazy=false or Plugin.init

We're able to store information about where the setup function will be called from and then we could query from Snacks lazy picker and add that to the path. Something like

diff --git a/lua/snacks/picker/source/lazy.lua b/lua/snacks/picker/source/lazy.lua
index 81fa0ed5..4cc1ac1a 100644
--- a/lua/snacks/picker/source/lazy.lua
+++ b/lua/snacks/picker/source/lazy.lua
@@ -10,6 +10,8 @@ function M.spec(opts, ctx)
       paths[#paths + 1] = modpath
     end)
   end
+  local setup_path = spec.plugins["lazy.nvim"]._.loaded.location
+  paths[#paths + 1] = setup_path
   local names = {} ---@type string[]
   for _, frag in pairs(spec.meta.fragments.fragments) do
     local name = frag.spec[1] or frag.name

With both of these Snacks lazy picker works even in a single init.lua file that I tried, but I've no idea if Folke would like this change in lazy.nvim. Feel free to also try it out if you like.

Let him decide what he wants to do.

dpetka2001 avatar Nov 20 '25 23:11 dpetka2001