forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfzflua.lua
More file actions
36 lines (31 loc) · 1.09 KB
/
Copy pathfzflua.lua
File metadata and controls
36 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local fzflua = require('fzf-lua')
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?: fzf-lua 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.exit_visual_mode()
opts = vim.tbl_extend('force', {
prompt = pick_actions.prompt .. '> ',
preview = fzflua.shell.raw_preview_action_cmd(function(items)
return string.format('echo "%s"', pick_actions.actions[items[1]].prompt)
end),
actions = {
['default'] = function(selected)
if not selected or vim.tbl_isempty(selected) then
return
end
vim.defer_fn(function()
chat.ask(pick_actions.actions[selected[1]].prompt, pick_actions.actions[selected[1]])
end, 100)
end,
},
}, opts or {})
fzflua.fzf_exec(vim.tbl_keys(pick_actions.actions), opts)
end
return M