Skip to content

Commit c5fb443

Browse files
Nguyễn Xuân HoàngNguyễn Xuân Hoàng
authored andcommitted
feat: add menu for snacks picker
1 parent e45f4ea commit c5fb443

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

lua/flutter-tools/menu.lua

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local lazy = require("flutter-tools.lazy")
22
local pickers = lazy.require("telescope.pickers") ---@module "telescope.pickers"
3+
local snack_picker = lazy.require("snacks.picker") ---@module "snakcs.picker"
34
local finders = lazy.require("telescope.finders") ---@module "telescope.finders"
45
local sorters = lazy.require("telescope.sorters") ---@module "telescope.sorters"
56
local actions = lazy.require("telescope.actions") ---@module "telescope.actions"
@@ -97,9 +98,8 @@ function M.get_config(items, user_opts, opts)
9798
}))
9899
end
99100

100-
function M.commands(opts)
101+
local function generate_commands_list()
101102
local cmds = {}
102-
103103
if commands.is_running() then
104104
cmds = {
105105
{
@@ -264,8 +264,31 @@ function M.commands(opts)
264264
},
265265
})
266266
end
267+
return cmds
268+
end
267269

268-
pickers.new(M.get_config(cmds, opts, { title = "Flutter tools commands" })):find()
270+
function M.commands(opts)
271+
pickers
272+
.new(M.get_config(generate_commands_list(), opts, { title = "Flutter tools commands" }))
273+
:find()
274+
end
275+
276+
function M.commands_snack()
277+
local cmds = generate_commands_list()
278+
for index, item in ipairs(cmds) do
279+
item.text = index .. ". " .. item.label
280+
end
281+
snack_picker.pick({
282+
title = "Flutter Tools",
283+
format = "text",
284+
autoselect = true,
285+
finder = function() return cmds end,
286+
confirm = function(picker, item)
287+
picker:close()
288+
if item and item.command then item.command() end
289+
end,
290+
layout = "select",
291+
})
269292
end
270293

271294
local function execute_fvm_use(bufnr)

0 commit comments

Comments
 (0)