feat(copilot-chat): enhanced rendering of the chat window
This commit is contained in:
@ -3,10 +3,16 @@ return {
|
|||||||
"CopilotC-Nvim/CopilotChat.nvim",
|
"CopilotC-Nvim/CopilotChat.nvim",
|
||||||
branch = "canary",
|
branch = "canary",
|
||||||
cmd = "CopilotChat",
|
cmd = "CopilotChat",
|
||||||
opts = {
|
opts = function()
|
||||||
|
local user = vim.env.USER or "User"
|
||||||
|
user = user:sub(1, 1):upper() .. user:sub(2)
|
||||||
|
return {
|
||||||
model = "gpt-4",
|
model = "gpt-4",
|
||||||
auto_insert_mode = true,
|
auto_insert_mode = true,
|
||||||
show_help = true,
|
show_help = true,
|
||||||
|
question_header = " " .. user .. " ",
|
||||||
|
answer_header = " Copilot ",
|
||||||
|
separator = "---",
|
||||||
window = {
|
window = {
|
||||||
width = 0.4,
|
width = 0.4,
|
||||||
},
|
},
|
||||||
@ -14,7 +20,8 @@ return {
|
|||||||
local select = require("CopilotChat.select")
|
local select = require("CopilotChat.select")
|
||||||
return select.visual(source) or select.buffer(source)
|
return select.visual(source) or select.buffer(source)
|
||||||
end,
|
end,
|
||||||
},
|
}
|
||||||
|
end,
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
"<leader>aa",
|
"<leader>aa",
|
||||||
@ -53,13 +60,40 @@ return {
|
|||||||
end,
|
end,
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local chat = require("CopilotChat")
|
local chat = require("CopilotChat")
|
||||||
|
local ns = vim.api.nvim_create_namespace("copilot-chat-text-hl")
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("BufEnter", {
|
vim.api.nvim_create_autocmd("BufEnter", {
|
||||||
pattern = "copilot-chat",
|
pattern = "copilot-chat",
|
||||||
callback = function()
|
callback = function(ev)
|
||||||
vim.opt_local.relativenumber = false
|
vim.opt_local.relativenumber = false
|
||||||
vim.opt_local.number = false
|
vim.opt_local.number = false
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, {
|
||||||
|
group = vim.api.nvim_create_augroup("copilot-chat-text-" .. ev.buf, { clear = true }),
|
||||||
|
buffer = ev.buf,
|
||||||
|
callback = function()
|
||||||
|
vim.api.nvim_buf_clear_namespace(ev.buf, ns, 0, -1)
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(ev.buf, 0, -1, false)
|
||||||
|
for l, line in ipairs(lines) do
|
||||||
|
if line:match(opts.separator .. "$") then
|
||||||
|
local sep = vim.fn.strwidth(line) - vim.fn.strwidth(opts.separator)
|
||||||
|
vim.api.nvim_buf_set_extmark(ev.buf, ns, l - 1, sep, {
|
||||||
|
virt_text_win_col = sep,
|
||||||
|
virt_text = { { string.rep("─", vim.go.columns), "@punctuation.special.markdown" } },
|
||||||
|
priority = 100,
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_extmark(ev.buf, ns, l - 1, 0, {
|
||||||
|
end_col = sep + 1,
|
||||||
|
hl_group = "@markup.heading.2.markdown",
|
||||||
|
priority = 100,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
chat.setup(opts)
|
chat.setup(opts)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user