diff --git a/lua/uv/init.lua b/lua/uv/init.lua index f19a0ab..e3c93c2 100644 --- a/lua/uv/init.lua +++ b/lua/uv/init.lua @@ -528,6 +528,14 @@ function M.setup_pickers() { text = "uv init", desc = "Initialize a new project" }, } end, + preview = function(ctx) + local cmd = ctx.item.text:match("^(uv %a+)") + if cmd then + Snacks.picker.preview.cmd(cmd .. " --help", ctx) + else + ctx.preview:set_lines({}) + end + end, format = function(item) return { { item.text .. " - " .. item.desc } } end, diff --git a/tests/uv_spec.lua b/tests/uv_spec.lua index 5b9c7f9..0328fd3 100644 --- a/tests/uv_spec.lua +++ b/tests/uv_spec.lua @@ -121,4 +121,19 @@ describe("uv.nvim", function() assert.are.equal("function", type(_G.run_command)) end) end) + + describe("snacks picker preview", function() + local pattern = "^(uv %a+)" + + it("extracts uv commands for help preview", function() + assert.are.equal("uv add", ("uv add [package]"):match(pattern)) + assert.are.equal("uv sync", ("uv sync --all-extras"):match(pattern)) + assert.are.equal("uv init", ("uv init"):match(pattern)) + end) + + it("returns nil for non-uv items", function() + assert.is_nil(("Run current file"):match(pattern)) + assert.is_nil(("Run selection"):match(pattern)) + end) + end) end)