forked from jellydn/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
37 lines (30 loc) · 1.16 KB
/
Copy pathinit.lua
File metadata and controls
37 lines (30 loc) · 1.16 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
37
local utils = require('CopilotChat.utils')
local M = {}
local default_prompts = {
Explain = 'Explain how it works.',
Tests = 'Briefly how selected code works then generate unit tests.',
}
-- Set up the plugin
---@param options (table | nil)
-- - mode: ('newbuffer' | 'split') default: newbuffer.
-- - prompts: (table?) default: default_prompts.
M.setup = function(options)
vim.g.copilot_chat_view_option = options and options.mode or 'newbuffer'
-- Merge the provided prompts with the default prompts
local prompts = vim.tbl_extend('force', default_prompts, options and options.prompts or {})
-- Loop through merged table and generate commands based on keys.
for key, value in pairs(prompts) do
utils.create_cmd('CopilotChat' .. key, function()
vim.cmd('CopilotChat ' .. value)
end, { nargs = '*', range = true })
end
-- Toggle between newbuffer and split
utils.create_cmd('CopilotChatToggleLayout', function()
if vim.g.copilot_chat_view_option == 'newbuffer' then
vim.g.copilot_chat_view_option = 'split'
else
vim.g.copilot_chat_view_option = 'newbuffer'
end
end, { nargs = '*', range = true })
end
return M