forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.lua
More file actions
138 lines (121 loc) · 3.46 KB
/
Copy pathdebug.lua
File metadata and controls
138 lines (121 loc) · 3.46 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
local async = require('plenary.async')
local log = require('plenary.log')
local utils = require('CopilotChat.utils')
local context = require('CopilotChat.context')
local Overlay = require('CopilotChat.ui.overlay')
local class = utils.class
---@return table<string>
local function build_debug_info()
local lines = {
'If you are facing issues, run `:checkhealth CopilotChat` and share the output.',
'',
'Log file path:',
'`' .. log.logfile .. '`',
'',
'Data directory:',
'`' .. vim.fn.stdpath('data') .. '`',
'',
'Config directory:',
'`' .. utils.config_path() .. '`',
'',
'Temp directory:',
'`' .. vim.fn.fnamemodify(os.tmpname(), ':h') .. '`',
'',
}
local buf = context.buffer(0)
if buf then
if buf.symbols then
table.insert(lines, 'Current buffer symbols:')
for _, symbol in ipairs(buf.symbols) do
table.insert(
lines,
string.format(
'%s `%s` (%s %s %s %s) - `%s`',
symbol.type,
symbol.name,
symbol.start_row,
symbol.start_col,
symbol.end_row,
symbol.end_col,
symbol.signature
)
)
end
table.insert(lines, '')
end
table.insert(lines, 'Current buffer outline:')
table.insert(lines, '`' .. buf.filename .. '`')
table.insert(lines, '```' .. buf.filetype)
local outline_lines = vim.split(buf.outline or buf.content, '\n')
for _, line in ipairs(outline_lines) do
table.insert(lines, line)
end
table.insert(lines, '```')
end
local files = context.files()
if files then
table.insert(lines, 'Current workspace file map:')
table.insert(lines, '```text')
for _, file in ipairs(files) do
for _, line in ipairs(vim.split(file.content, '\n')) do
table.insert(lines, line)
end
end
table.insert(lines, '```')
end
return lines
end
---@class CopilotChat.ui.Debug : CopilotChat.ui.Overlay
local Debug = class(function(self)
Overlay.init(self, 'copilot-debug', nil, function(bufnr)
vim.keymap.set('n', 'q', function()
vim.api.nvim_win_close(0, true)
end, { buffer = bufnr })
end)
end, Overlay)
function Debug:close()
if not self.winnr then
return
end
if vim.api.nvim_win_is_valid(self.winnr) then
vim.api.nvim_win_close(self.winnr, true)
end
self.winnr = nil
end
function Debug:open()
self:validate()
self:close()
async.run(function()
local lines = build_debug_info()
async.util.scheduler()
local height = math.min(vim.o.lines - 3, #lines)
local width = 0
for _, line in ipairs(lines) do
width = math.max(width, #line)
end
local win_opts = {
title = 'CopilotChat.nvim Debug Info',
relative = 'editor',
width = width,
height = height,
row = math.floor((vim.o.lines - height) / 2) - 1,
col = math.floor((vim.o.columns - width) / 2),
style = 'minimal',
border = 'rounded',
zindex = 50,
}
if not utils.is_stable() then
win_opts.footer = "Press 'q' to close this window."
end
-- Open window
self.winnr = vim.api.nvim_open_win(self.bufnr, true, win_opts)
vim.wo[self.winnr].wrap = true
vim.wo[self.winnr].linebreak = true
vim.wo[self.winnr].cursorline = true
vim.wo[self.winnr].conceallevel = 2
-- Show content
self:show(table.concat(lines, '\n'), self.winnr, 'markdown')
vim.api.nvim_win_set_cursor(self.winnr, { 1, 0 })
end)
end
return Debug