forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debuginfo.lua
81 lines (72 loc) · 2.23 KB
/
debuginfo.lua
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
local log = require('plenary.log')
local utils = require('CopilotChat.utils')
local context = require('CopilotChat.context')
local M = {}
function M.open()
local lines = {
'If you are facing issues, run `:checkhealth CopilotChat` and share the output.',
'',
'Log file path:',
'`' .. log.logfile .. '`',
'',
'Temp directory:',
'`' .. vim.fn.fnamemodify(os.tmpname(), ':h') .. '`',
'',
'Data directory:',
'`' .. vim.fn.stdpath('data') .. '`',
'',
}
local outline = context.outline(vim.api.nvim_get_current_buf())
if outline then
table.insert(lines, 'Current buffer outline:')
table.insert(lines, '`' .. outline.filename .. '`')
table.insert(lines, '```' .. outline.filetype)
local outline_lines = vim.split(outline.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
local width = 0
for _, line in ipairs(lines) do
width = math.max(width, #line)
end
local height = math.min(vim.o.lines - 3, #lines)
local opts = {
title = 'CopilotChat.nvim Debug Info',
relative = 'editor',
width = width,
height = height,
row = (vim.o.lines - height) / 2 - 1,
col = (vim.o.columns - width) / 2,
style = 'minimal',
border = 'rounded',
}
if not utils.is_stable() then
opts.footer = "Press 'q' to close this window."
end
local bufnr = vim.api.nvim_create_buf(false, true)
vim.bo[bufnr].syntax = 'markdown'
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
vim.bo[bufnr].modifiable = false
vim.treesitter.start(bufnr, 'markdown')
local win = vim.api.nvim_open_win(bufnr, true, opts)
vim.wo[win].wrap = true
vim.wo[win].linebreak = true
vim.wo[win].cursorline = true
vim.wo[win].conceallevel = 2
-- Bind 'q' to close the window
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', '<cmd>close<CR>', { noremap = true, silent = true })
end
return M