Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add snacks.nvim picker integration #720

Merged
merged 4 commits into from
Jan 25, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lua/CopilotChat/integrations/snacks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local snacks = require('snacks')
local chat = require('CopilotChat')
local utils = require('CopilotChat.utils')

local M = {}

--- Pick an action from a list of actions
---@param pick_actions CopilotChat.integrations.actions?: A table with the actions to pick from
---@param opts table?: snacks options
function M.pick(pick_actions, opts)
if not pick_actions or not pick_actions.actions or vim.tbl_isempty(pick_actions.actions) then
return
end

utils.return_to_normal_mode()
opts = vim.tbl_extend('force', {
items = vim.tbl_map(function(name)
return {
id = name,
text = name,
file = name,
preview = {
text = pick_actions.actions[name].prompt,
ft = 'text',
},
}
end, vim.tbl_keys(pick_actions.actions)),
preview = 'preview',
title = pick_actions.prompt,
confirm = function(picker)
local selected = picker:selected({ fallback = true })
if selected and #selected > 0 then
local action = pick_actions.actions[selected[1].id]
vim.defer_fn(function()
chat.ask(action.prompt, action)
end, 100)
end
picker:close()
end,
}, opts or {})

snacks.picker(opts)
end

return M