You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing an issue with CopilotChat in normal mode where it fails to capture the current buffer's content. Instead of performing the requested operation, it responds with: "I'm sorry, but I can't provide the explanation you're asking for because you haven't provided any code to explain. Could you please provide the code you want explained?" Here is the code snippet I've been working with:
local prompts = {
-- Code related prompts
Explain = "Please explain how the following code works.",
Review = "Please review the following code and provide suggestions for improvement.",
Tests = "Please explain how the selected code works, then generate unit tests for it.",
Refactor = "Please refactor the following code to improve its clarity and readability.",
FixCode = "Please fix the following code to make it work as intended.",
FixError = "Please explain the error in the following text and provide a solution.",
BetterNamings = "Please provide better names for the following variables and functions.",
Documentation = "Please provide documentation for the following code.",
SwaggerApiDocs = "Please provide documentation for the following API using Swagger.",
SwaggerJsDocs = "Please write JSDoc for the following API using Swagger.",
-- Text related prompts
Summarize = "Please summarize the following text.",
Spelling = "Please correct any grammar and spelling errors in the following text.",
Wording = "Please improve the grammar and wording of the following text.",
Concise = "Please rewrite the following text to make it more concise.",
}
return {
{
"folke/which-key.nvim",
optional = true,
opts = {
defaults = {
["<leader>a"] = { name = "+AI" },
["gm"] = { name = "+CopilotChat" },
},
},
},
{
"zbirenbaum/copilot.lua",
event = "InsertEnter",
optional = true,
keys = {
{
"<leader>ap",
"<cmd>Copilot panel<cr>",
desc = "Copilot Panel",
},
},
opts = {
panel = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "<M-Tab>",
open = "<M-space>",
},
},
suggestion = {
enabled = true,
auto_trigger = false,
debounce = 75,
keymap = {
accept = "<C-f>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
},
filetypes = {
yaml = false,
markdown = true,
help = false,
gitcommit = false,
gitrebase = false,
hgcommit = false,
svn = false,
cvs = false,
["."] = false,
},
copilot_node_command = "node", -- Node version must be < 18
cmp = {
enabled = true,
method = "getCompletionsCycling",
},
-- plugin_manager_path = vim.fn.stdpath "data" .. "/site/pack/packer",
server_opts_overrides = {
-- trace = "verbose",
settings = {
advanced = {
-- listCount = 10, -- #completions for panel
inlineSuggestCount = 3, -- #completions for getCompletions
},
},
},
},
},
{
"CopilotC-Nvim/CopilotChat.nvim",
branch = "canary",
-- version = "v2.4.3",
-- event = "VeryLazy",
dependencies = {
{ "zbirenbaum/copilot.lua" }, -- or github/copilot.vim
{ "nvim-lua/plenary.nvim" }, -- for curl, log wrapper
},
opts = {
question_header = "## User ",
answer_header = "## Copilot ",
error_header = "## Error ",
separator = " ", -- Separator to use in chat
prompts = prompts,
show_help = false, -- Show help in virtual text, set to true if that's 1st time using Copilot Chat
mappings = {
-- Use tab for completion
complete = {
detail = "Use @<Tab> or /<Tab> for options.",
insert = "<Tab>",
},
close = {
normal = "q",
insert = "<C-c>",
},
-- Reset the chat buffer
reset = {
normal = "<C-l>",
insert = "<C-l>",
},
-- Submit the prompt to Copilot
submit_prompt = {
normal = "<CR>",
insert = "<C-CR>",
},
-- Accept the diff
accept_diff = {
normal = "<C-y>",
insert = "<C-y>",
},
-- Yank the diff in the response to register
yank_diff = {
normal = "gmy",
},
-- Show the diff
show_diff = {
normal = "gmd",
},
-- Show the prompt
show_system_prompt = {
normal = "gmp",
},
-- Show the user selection
show_user_selection = {
normal = "gms",
},
},
},
keys = {
-- Show help actions with telescope
{
"<leader>ah",
function()
local actions = require("CopilotChat.actions")
require("CopilotChat.integrations.telescope").pick(actions.help_actions())
end,
desc = "CopilotChat - Help actions",
},
-- Show prompts actions with telescope
{
"<leader>aa",
function()
local actions = require("CopilotChat.actions")
require("CopilotChat.integrations.telescope").pick(actions.prompt_actions())
end,
desc = "CopilotChat - Prompt actions",
},
{
"<leader>aa",
":lua require('CopilotChat.integrations.telescope').pick(require('CopilotChat.actions').prompt_actions({selection = require('CopilotChat.select').visual}))<CR>",
mode = "x",
desc = "CopilotChat - Prompt actions",
},
-- Code related commands
{ "<leader>ae", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
{ "<leader>at", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{ "<leader>ar", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
{ "<leader>aR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
{ "<leader>an", "<cmd>CopilotChatBetterNamings<cr>", desc = "CopilotChat - Better Naming" },
-- Chat with Copilot in visual mode
{
"<leader>av",
":CopilotChatVisual",
mode = "x",
desc = "CopilotChat - Open in vertical split",
},
{
"<leader>ax",
":CopilotChatInline<cr>",
mode = "x",
desc = "CopilotChat - Inline chat",
},
-- Custom input for CopilotChat
{
"<leader>ai",
function()
local input = vim.fn.input("Ask Copilot: ")
if input ~= "" then
vim.cmd("CopilotChat " .. input)
end
end,
desc = "CopilotChat - Ask input",
},
-- Generate commit message based on the git diff
{
"<leader>am",
"<cmd>CopilotChatCommit<cr>",
desc = "CopilotChat - Generate commit message for all changes",
},
{
"<leader>aM",
"<cmd>CopilotChatCommitStaged<cr>",
desc = "CopilotChat - Generate commit message for staged changes",
},
-- Quick chat with Copilot
{
"<leader>aq",
function()
local input = vim.fn.input("Quick Chat: ")
if input ~= "" then
vim.cmd("CopilotChatBuffer " .. input)
end
end,
desc = "CopilotChat - Quick chat",
},
-- Debug
{ "<leader>ad", "<cmd>CopilotChatDebugInfo<cr>", desc = "CopilotChat - Debug Info" },
-- Fix the issue with diagnostic
{ "<leader>af", "<cmd>CopilotChatFixDiagnostic<cr>", desc = "CopilotChat - Fix Diagnostic" },
-- Clear buffer and chat history
{ "<leader>al", "<cmd>CopilotChatReset<cr>", desc = "CopilotChat - Clear buffer and chat history" },
-- Toggle Copilot Chat Vsplit
{ "<leader>at", "<cmd>CopilotChatToggle<cr>", desc = "CopilotChat - Toggle" },
{ "gmd", desc = "Show diff" },
{ "gmp", desc = "System prompt" },
{ "gms", desc = "Show selection" },
{ "gmy", desc = "Yank diff" },
},
config = function(_, opts)
local chat = require("CopilotChat")
local select = require("CopilotChat.select")
-- Use unnamed register for the selection
opts.selection = select.unnamed
-- Override the git prompts message
opts.prompts.Commit = {
prompt = "Write commit message for the change with commitizen convention",
selection = select.gitdiff,
}
opts.prompts.CommitStaged = {
prompt = "Write commit message for the change with commitizen convention",
selection = function(source)
return select.gitdiff(source, true)
end,
}
chat.setup(opts)
vim.api.nvim_create_user_command("CopilotChatVisual", function(args)
chat.ask(args.args, { selection = select.visual })
end, { nargs = "*", range = true })
-- Inline chat with Copilot
vim.api.nvim_create_user_command("CopilotChatInline", function(args)
chat.ask(args.args, {
selection = select.visual,
window = {
layout = "float",
relative = "cursor",
width = 1,
height = 0.4,
row = 1,
},
})
end, { nargs = "*", range = true })
-- Restore CopilotChatBuffer
vim.api.nvim_create_user_command("CopilotChatBuffer", function(args)
chat.ask(args.args, { selection = select.buffer })
end, { nargs = "*", range = true })
-- Custom buffer for CopilotChat
vim.api.nvim_create_autocmd("BufEnter", {
pattern = "copilot-*",
callback = function()
vim.opt_local.relativenumber = true
vim.opt_local.number = true
-- Get current filetype and set it to markdown if the current filetype is copilot-chat
local ft = vim.bo.filetype
if ft == "copilot-chat" then
vim.bo.filetype = "markdown"
end
end,
})
end,
},
{
"folke/edgy.nvim",
optional = true,
opts = {
right = {
{
title = "CopilotChat.nvim",
ft = "copilot-chat",
size = { width = 0.5 },
-- exclude floating windows
filter = function(buf, win)
return vim.api.nvim_win_get_config(win).relative == ""
end,
},
},
},
},
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am experiencing an issue with CopilotChat in normal mode where it fails to capture the current buffer's content. Instead of performing the requested operation, it responds with: "I'm sorry, but I can't provide the explanation you're asking for because you haven't provided any code to explain. Could you please provide the code you want explained?" Here is the code snippet I've been working with:
Beta Was this translation helpful? Give feedback.
All reactions