diff --git a/README.md b/README.md index 46c6022c..71812b99 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/cspell-tool.txt b/cspell-tool.txt index 73288a14..400bb5a2 100644 --- a/cspell-tool.txt +++ b/cspell-tool.txt @@ -65,4 +65,6 @@ noautocmd roleplay vusted luarocks -isort \ No newline at end of file +isort +checkhealth +sysname \ No newline at end of file diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index d3058d41..85510023 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -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', + 'close', + { 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 + 'closeedit ' + .. rplugin_path + .. '', + { noremap = true, silent = true } + ) + end, { + nargs = '*', + range = true, + }) + utils.log_info( 'Execute ":UpdateRemotePlugins" and restart Neovim before starting a chat with Copilot.' ) diff --git a/lua/CopilotChat/utils.lua b/lua/CopilotChat/utils.lua index 3402d5b6..472c411e 100644 --- a/lua/CopilotChat/utils.lua +++ b/lua/CopilotChat/utils.lua @@ -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