Skip to content

Commit 754d5ac

Browse files
committed
refactor: streamline debug info into info mapping
Move debug info functionality into info mapping and remove separate debug UI window. This simplifies the codebase while keeping all debugging functionality available through a unified interface. The debug info now includes: - Log file location - History file location - Temp files directory - Model and agent info - System prompt details BREAKING CHANGE: Removes CopilotChatDebugInfo command. Use `gi` in chat instead. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 814dd49 commit 754d5ac

5 files changed

Lines changed: 17 additions & 162 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ Commands are used to control the chat interface:
116116
| `:CopilotChatReset` | Reset chat window |
117117
| `:CopilotChatSave <name>?` | Save chat history |
118118
| `:CopilotChatLoad <name>?` | Load chat history |
119-
| `:CopilotChatDebugInfo` | Show debug info |
120119
| `:CopilotChatModels` | View/select available models |
121120
| `:CopilotChatAgents` | View/select available agents |
122121
| `:CopilotChat<PromptName>` | Use specific prompt template |
@@ -500,6 +499,8 @@ Below are all available configuration options with their default values:
500499
allow_insecure = false, -- Allow insecure server connections
501500

502501
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
502+
503+
log_path = vim.fn.stdpath('state') .. '/CopilotChat.log', -- Default path to log file
503504
history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
504505

505506
question_header = '# User ', -- Header to use for user questions

lua/CopilotChat/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ local select = require('CopilotChat.select')
4040
---@field proxy string?
4141
---@field allow_insecure boolean?
4242
---@field chat_autocomplete boolean?
43+
---@field log_path string?
4344
---@field history_path string?
4445
---@field question_header string?
4546
---@field answer_header string?
@@ -101,6 +102,8 @@ return {
101102
allow_insecure = false, -- Allow insecure server connections
102103

103104
chat_autocomplete = true, -- Enable chat autocompletion (when disabled, requires manual `mappings.complete` trigger)
105+
106+
log_path = vim.fn.stdpath('state') .. '/CopilotChat.log', -- Default path to log file
104107
history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
105108

106109
question_header = '## User ', -- Header to use for user questions

lua/CopilotChat/config/mappings.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,22 @@ return {
352352
local system_prompt = config.system_prompt
353353

354354
async.run(function()
355-
local selected_agent = copilot.resolve_agent(prompt, config)
356-
local selected_model = copilot.resolve_model(prompt, config)
355+
local _, selected_agent = pcall(copilot.resolve_agent, prompt, config)
356+
local _, selected_model = pcall(copilot.resolve_model, prompt, config)
357+
358+
async.util.scheduler()
359+
table.insert(lines, '**Logs**: `' .. chat.config.log_path .. '`')
360+
table.insert(lines, '**History**: `' .. chat.config.history_path .. '`')
361+
table.insert(lines, '**Temp Files**: `' .. vim.fn.fnamemodify(os.tmpname(), ':h') .. '`')
362+
table.insert(lines, '')
357363

358364
if selected_model then
359-
table.insert(lines, '**Model**')
360-
table.insert(lines, '```')
361-
table.insert(lines, selected_model)
362-
table.insert(lines, '```')
365+
table.insert(lines, '**Model**: `' .. selected_model .. '`')
363366
table.insert(lines, '')
364367
end
365368

366369
if selected_agent then
367-
table.insert(lines, '**Agent**')
368-
table.insert(lines, '```')
369-
table.insert(lines, selected_agent)
370-
table.insert(lines, '```')
370+
table.insert(lines, '**Agent**: `' .. selected_agent .. '`')
371371
table.insert(lines, '')
372372
end
373373

@@ -381,7 +381,6 @@ return {
381381
table.insert(lines, '')
382382
end
383383

384-
async.util.scheduler()
385384
overlay:show(vim.trim(table.concat(lines, '\n')) .. '\n', chat.winnr, 'markdown')
386385
end)
387386
end,

lua/CopilotChat/init.lua

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ local WORD = '([^%s]+)'
1818
--- @field last_response string?
1919
--- @field chat CopilotChat.ui.Chat?
2020
--- @field diff CopilotChat.ui.Diff?
21-
--- @field debug CopilotChat.ui.Debug?
2221
--- @field overlay CopilotChat.ui.Overlay?
2322
local state = {
2423
client = nil,
@@ -34,7 +33,6 @@ local state = {
3433
chat = nil,
3534
diff = nil,
3635
overlay = nil,
37-
debug = nil,
3836
}
3937

4038
--- Highlights the selection in the source buffer.
@@ -785,13 +783,12 @@ end
785783
function M.log_level(level)
786784
M.config.log_level = level
787785
M.config.debug = level == 'debug'
788-
local logfile = string.format('%s/%s.log', vim.fn.stdpath('state'), PLUGIN_NAME)
786+
789787
log.new({
790788
plugin = PLUGIN_NAME,
791789
level = level,
792-
outfile = logfile,
790+
outfile = M.config.log_path,
793791
}, true)
794-
log.logfile = logfile
795792
end
796793

797794
--- Set up the plugin
@@ -881,10 +878,6 @@ function M.setup(config)
881878
end)
882879
end)
883880

884-
if not state.debug then
885-
state.debug = require('CopilotChat.ui.debug')()
886-
end
887-
888881
if state.diff then
889882
state.diff:delete()
890883
end
@@ -1023,9 +1016,6 @@ function M.setup(config)
10231016
vim.api.nvim_create_user_command('CopilotChatReset', function()
10241017
M.reset()
10251018
end, { force = true })
1026-
vim.api.nvim_create_user_command('CopilotChatDebugInfo', function()
1027-
state.debug:open()
1028-
end, { force = true })
10291019

10301020
local function complete_load()
10311021
local options = vim.tbl_map(function(file)

lua/CopilotChat/ui/debug.lua

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)