Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

feat: add CopilotChatDebugInfo command #51

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ For further reference, you can view @jellydn's [configuration](https://github.co

## Receipts

### Debugging with `:messages` and `:CopilotChatDebugInfo`

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.

[![Debug Info](https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif)](https://gyazo.com/bf00e700bcee1b77bcbf7b516b552521)

### How to setup with `which-key.nvim`

A special thanks to @ecosse3 for the configuration of [which-key](https://github.com/jellydn/CopilotChat.nvim/issues/30).
Expand Down
4 changes: 3 additions & 1 deletion cspell-tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ noautocmd
roleplay
vusted
luarocks
isort
isort
checkhealth
sysname
62 changes: 62 additions & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,68 @@ M.setup = function(options)
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.'
)
Expand Down
19 changes: 19 additions & 0 deletions lua/CopilotChat/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ local M = {}

local log = require('CopilotChat.vlog')

--- Get the log file path
---@return string
M.get_log_file_path = function()
return log.get_log_file()
end

-- The CopilotChat.nvim is built using remote plugins.
-- This is the path to the rplugin.vim file.
-- Refer https://neovim.io/doc/user/remote_plugin.html#%3AUpdateRemotePlugins
-- @return string
M.get_remote_plugins_path = function()
local os = vim.loop.os_uname().sysname
if os == 'Linux' or os == 'Darwin' then
return '~/.local/share/nvim/rplugin.vim'
elseif os == 'Windows' then
return '~/AppData/Local/nvim/rplugin.vim'
end
end

--- Create custom command
---@param cmd string The command name
---@param func function The function to execute
Expand Down
Loading