From 67beb093c5a7cc559f9d3277458fdcc356304f29 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Wed, 8 Oct 2025 18:57:23 +0300 Subject: [PATCH] feat: add snacks.picker support --- lua/http-codes.lua | 10 +++++++--- lua/http-codes/snacks.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 lua/http-codes/snacks.lua diff --git a/lua/http-codes.lua b/lua/http-codes.lua index 7e578d9..47c17c2 100644 --- a/lua/http-codes.lua +++ b/lua/http-codes.lua @@ -24,19 +24,21 @@ local function init() if not config.use then if pcall(require, 'fzf-lua') then config.use = 'fzf-lua' + elseif pcall(require, 'snacks') then + config.use = 'snacks' elseif pcall(require, 'telescope') then config.use = 'telescope' end end if not config.use then - vim.notify_once('http-codes.nvim: install fzf-lua or telescope.nvim', vim.log.levels.ERROR) + vim.notify_once('http-codes.nvim: install fzf-lua, snacks.nvim, or telescope.nvim', vim.log.levels.ERROR) return false end - if not vim.tbl_contains({ 'fzf-lua', 'telescope' }, config.use) then + if not vim.tbl_contains({ 'fzf-lua', 'snacks', 'telescope' }, config.use) then vim.notify_once( - "http-codes.nvim: 'use' must be 'fzf-lua' or 'telescope'", + "http-codes.nvim: 'use' must be 'fzf-lua', 'snacks', or 'telescope'", vim.log.levels.ERROR ) return false @@ -59,6 +61,8 @@ function M.pick() require('telescope').extensions.http.list(config.open_url) elseif config.use == 'fzf-lua' then require('http-codes.fzf-lua').pick(config.open_url) + elseif config.use == 'snacks' then + require('http-codes.snacks').pick(config.open_url) end end diff --git a/lua/http-codes/snacks.lua b/lua/http-codes/snacks.lua new file mode 100644 index 0000000..1668724 --- /dev/null +++ b/lua/http-codes/snacks.lua @@ -0,0 +1,35 @@ +local codes = require 'http-codes.codes' +local cached_items = nil + +local function codes_to_snack_items(codes) + if cached_items then return cached_items end + + local items = {} + + local idx = 1 + for status, _ in pairs(codes) do + table.insert(items, { idx = idx, text = status }) + idx = idx + 1 + end + cached_items = items + return items +end + +return { + pick = function(open_url) + require('snacks.picker').pick(nil, { + title = 'HTTP Codes', + items = codes_to_snack_items(codes), + format = 'text', + layout = { + preset = 'select', + hidden = { 'preview' }, + }, + confirm = function(picker, item) + local link = codes[item.text] + picker:close() + vim.fn.jobstart(open_url:format(link)) + end, + }) + end, +}