Skip to content

Commit 89b6276

Browse files
authored
feat: add CopilotChatDebugInfo command (#51)
* feat: add CopilotChatDebugInfo command chore: add remote plugin path to util * docs: add debug command to receipts
1 parent 6a17928 commit 89b6276

4 files changed

Lines changed: 90 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ For further reference, you can view @jellydn's [configuration](https://github.co
176176

177177
## Receipts
178178

179+
### Debugging with `:messages` and `:CopilotChatDebugInfo`
180+
181+
If you encounter any issues, you can run the command `:messages` to inspect the log. You can also run the command `:CopilotChatDebugInfo` to inspect the debug information.
182+
183+
[![Debug Info](https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif)](https://gyazo.com/bf00e700bcee1b77bcbf7b516b552521)
184+
179185
### How to setup with `which-key.nvim`
180186

181187
A special thanks to @ecosse3 for the configuration of [which-key](https://github.com/jellydn/CopilotChat.nvim/issues/30).

cspell-tool.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ noautocmd
6565
roleplay
6666
vusted
6767
luarocks
68-
isort
68+
isort
69+
checkhealth
70+
sysname

lua/CopilotChat/init.lua

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,68 @@ M.setup = function(options)
3030
end, { nargs = '*', range = true })
3131
end
3232

33+
-- Show debug info
34+
utils.create_cmd('CopilotChatDebugInfo', function()
35+
-- Get the log file path
36+
local log_file_path = utils.get_log_file_path()
37+
38+
-- Get the rplugin path
39+
local rplugin_path = utils.get_remote_plugins_path()
40+
41+
-- Create a popup with the log file path
42+
local lines = {
43+
'CopilotChat.nvim Info:',
44+
'- Log file path: ' .. log_file_path,
45+
'- Rplugin path: ' .. rplugin_path,
46+
'If you are facing issues, run `:checkhealth CopilotChat` and share the output.',
47+
'There is a common issue is "Ambiguous use of user-defined command". Please check the pin issues on the repository.',
48+
'Press `q` to close this window.',
49+
'Press `?` to open the rplugin file.',
50+
}
51+
52+
local width = 0
53+
for _, line in ipairs(lines) do
54+
width = math.max(width, #line)
55+
end
56+
local height = #lines
57+
local opts = {
58+
relative = 'editor',
59+
width = width + 4,
60+
height = height + 2,
61+
row = (vim.o.lines - height) / 2 - 1,
62+
col = (vim.o.columns - width) / 2,
63+
style = 'minimal',
64+
border = 'rounded',
65+
}
66+
local bufnr = vim.api.nvim_create_buf(false, true)
67+
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
68+
vim.api.nvim_open_win(bufnr, true, opts)
69+
70+
-- Bind 'q' to close the window
71+
vim.api.nvim_buf_set_keymap(
72+
bufnr,
73+
'n',
74+
'q',
75+
'<cmd>close<CR>',
76+
{ noremap = true, silent = true }
77+
)
78+
79+
-- Bind `?` to open remote plugin detail
80+
vim.api.nvim_buf_set_keymap(
81+
bufnr,
82+
'n',
83+
'?',
84+
-- Close the current window and open the rplugin file
85+
'<cmd>close<CR><cmd>edit '
86+
.. rplugin_path
87+
.. '<CR>',
88+
{ noremap = true, silent = true }
89+
)
90+
end, {
91+
nargs = '*',
92+
range = true,
93+
})
94+
3395
utils.log_info(
3496
'Execute ":UpdateRemotePlugins" and restart Neovim before starting a chat with Copilot.'
3597
)

lua/CopilotChat/utils.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ local M = {}
22

33
local log = require('CopilotChat.vlog')
44

5+
--- Get the log file path
6+
---@return string
7+
M.get_log_file_path = function()
8+
return log.get_log_file()
9+
end
10+
11+
-- The CopilotChat.nvim is built using remote plugins.
12+
-- This is the path to the rplugin.vim file.
13+
-- Refer https://neovim.io/doc/user/remote_plugin.html#%3AUpdateRemotePlugins
14+
-- @return string
15+
M.get_remote_plugins_path = function()
16+
local os = vim.loop.os_uname().sysname
17+
if os == 'Linux' or os == 'Darwin' then
18+
return '~/.local/share/nvim/rplugin.vim'
19+
elseif os == 'Windows' then
20+
return '~/AppData/Local/nvim/rplugin.vim'
21+
end
22+
end
23+
524
--- Create custom command
625
---@param cmd string The command name
726
---@param func function The function to execute

0 commit comments

Comments
 (0)