From 37c46e8d9ad4141424de163d880b666ec1654520 Mon Sep 17 00:00:00 2001 From: Naowal Rahman Date: Wed, 28 Jan 2026 23:02:55 -0500 Subject: [PATCH 1/3] feat(snacks): add snacks.picker action integration --- lua/opencode/integrations/picker/snacks.lua | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lua/opencode/integrations/picker/snacks.lua diff --git a/lua/opencode/integrations/picker/snacks.lua b/lua/opencode/integrations/picker/snacks.lua new file mode 100644 index 0000000..2db2fb3 --- /dev/null +++ b/lua/opencode/integrations/picker/snacks.lua @@ -0,0 +1,31 @@ +---@module 'snacks' + +---Snacks picker integration for opencode. +---@class opencode.integrations.picker.snacks +local M = {} + +---Send selected picker items to opencode prompt. +---@param picker snacks.Picker +function M.opencode_send(picker) + local entries = {} + for _, item in ipairs(picker:selected({ fallback = true })) do + local entry = "" + if item.text and item.text ~= "" then -- Includes file reference + entry = item.text + end + -- Append line numbers if available + if item.file and item.pos then + local line_ref = ("L%d"):format(item.pos[1]) + if item.end_pos and item.end_pos[1] ~= item.pos[1] then + line_ref = line_ref .. ("-L%d"):format(item.end_pos[1]) + end + entry = entry .. " " .. line_ref + end + if entry ~= "" then + entries[#entries + 1] = entry + end + end + require("opencode").prompt(table.concat(entries, "\n") .. "\n") +end + +return M From de1f887923bc0212ea2e70b22fd838de8e52aa6a Mon Sep 17 00:00:00 2001 From: Naowal Rahman Date: Wed, 4 Feb 2026 17:09:24 -0500 Subject: [PATCH 2/3] Account for zero entries edge case Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lua/opencode/integrations/picker/snacks.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/opencode/integrations/picker/snacks.lua b/lua/opencode/integrations/picker/snacks.lua index 2db2fb3..e5b42e2 100644 --- a/lua/opencode/integrations/picker/snacks.lua +++ b/lua/opencode/integrations/picker/snacks.lua @@ -25,6 +25,9 @@ function M.opencode_send(picker) entries[#entries + 1] = entry end end + if #entries == 0 then + return + end require("opencode").prompt(table.concat(entries, "\n") .. "\n") end From 2f1c55e3b1bfb6cb32554a02191eaaf52ddf6cae Mon Sep 17 00:00:00 2001 From: Naowal Rahman Date: Sat, 7 Feb 2026 11:36:41 -0500 Subject: [PATCH 3/3] refactor(snacks): use Context.format in opencode_send() --- lua/opencode/integrations/picker/snacks.lua | 25 ++++++++------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lua/opencode/integrations/picker/snacks.lua b/lua/opencode/integrations/picker/snacks.lua index e5b42e2..e44569f 100644 --- a/lua/opencode/integrations/picker/snacks.lua +++ b/lua/opencode/integrations/picker/snacks.lua @@ -7,28 +7,21 @@ local M = {} ---Send selected picker items to opencode prompt. ---@param picker snacks.Picker function M.opencode_send(picker) + local Context = require("opencode.context") local entries = {} for _, item in ipairs(picker:selected({ fallback = true })) do - local entry = "" - if item.text and item.text ~= "" then -- Includes file reference - entry = item.text - end - -- Append line numbers if available - if item.file and item.pos then - local line_ref = ("L%d"):format(item.pos[1]) - if item.end_pos and item.end_pos[1] ~= item.pos[1] then - line_ref = line_ref .. ("-L%d"):format(item.end_pos[1]) - end - entry = entry .. " " .. line_ref - end - if entry ~= "" then - entries[#entries + 1] = entry - end + entries[#entries + 1] = Context.format({ + path = item.text, + start_line = item.pos and item.pos[1] or nil, + start_col = item.pos and item.pos[2] or nil, + end_line = item.end_pos and item.end_pos[1] or nil, + end_col = item.end_pos and item.end_pos[2] or nil, + }) end if #entries == 0 then return end - require("opencode").prompt(table.concat(entries, "\n") .. "\n") + require("opencode").prompt(table.concat(entries, "\n")) end return M