forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
104 lines (90 loc) · 3.2 KB
/
init.lua
File metadata and controls
104 lines (90 loc) · 3.2 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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.',
}
_COPILOT_CHAT_GLOBAL_CONFIG = {}
-- Set up the plugin
---@param options (table | nil)
-- - show_help: ('yes' | 'no') default: 'yes'.
-- - disable_extra_info: ('yes' | 'no') default: 'yes'.
-- - prompts: (table?) default: default_prompts.
-- - debug: (boolean?) default: false.
M.setup = function(options)
vim.g.copilot_chat_show_help = options and options.show_help or 'yes'
vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or 'yes'
vim.g.copilot_chat_proxy = options and options.proxy or ''
local debug = options and options.debug or false
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug
-- Merge the provided prompts with the default prompts
local prompts = vim.tbl_extend('force', default_prompts, options and options.prompts or {})
vim.g.copilot_chat_user_prompts = prompts
-- 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
-- Show debug info
utils.create_cmd('CopilotChatDebugInfo', function()
-- Get the log file path
local log_file_path = utils.get_log_file_path()
-- Get the rplugin path
local rplugin_path = utils.get_remote_plugins_path()
-- Create a popup with the log file path
local lines = {
'CopilotChat.nvim Info:',
'- Log file path: ' .. log_file_path,
'- Rplugin path: ' .. rplugin_path,
'If you are facing issues, run `:checkhealth CopilotChat` and share the output.',
'There is a common issue is "Ambiguous use of user-defined command". Please check the pin issues on the repository.',
'Press `q` to close this window.',
'Press `?` to open the rplugin file.',
}
local width = 0
for _, line in ipairs(lines) do
width = math.max(width, #line)
end
local height = #lines
local opts = {
relative = 'editor',
width = width + 4,
height = height + 2,
row = (vim.o.lines - height) / 2 - 1,
col = (vim.o.columns - width) / 2,
style = 'minimal',
border = 'rounded',
}
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
vim.api.nvim_open_win(bufnr, true, opts)
-- Bind 'q' to close the window
vim.api.nvim_buf_set_keymap(
bufnr,
'n',
'q',
'<cmd>close<CR>',
{ noremap = true, silent = true }
)
-- Bind `?` to open remote plugin detail
vim.api.nvim_buf_set_keymap(
bufnr,
'n',
'?',
-- Close the current window and open the rplugin file
'<cmd>close<CR><cmd>edit '
.. rplugin_path
.. '<CR>',
{ noremap = true, silent = true }
)
end, {
nargs = '*',
range = true,
})
utils.log_info(
'Execute ":UpdateRemotePlugins" and restart Neovim before starting a chat with Copilot.'
)
utils.log_info('If issues arise, run ":healthcheck" and share the output.')
end
return M