diff --git a/README.md b/README.md index 7c60cc84..34efe370 100644 --- a/README.md +++ b/README.md @@ -501,6 +501,30 @@ Requires [fzf-lua](https://github.com/ibhagwan/fzf-lua) plugin to be installed. +
+nvim-cmp integration + +Requires [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) plugin to be installed (and properly configured). + +```lua +-- Registers copilot-chat source and enables it for copilot-chat filetype (so copilot chat window) +require("CopilotChat.integrations.cmp").setup() + +-- You might also want to disable default complete mapping for copilot chat when doing this +require('CopilotChat').setup({ + mappings = { + complete = { + insert = '', + }, + }, + -- rest of your config +}) +``` + +![image](https://github.com/CopilotC-Nvim/CopilotChat.nvim/assets/5115805/063fc99f-a4b2-4187-a065-0fdd287ebee2) + +
+ ## Roadmap (Wishlist) - Use indexed vector database with current workspace for better context selection diff --git a/lua/CopilotChat/integrations/cmp.lua b/lua/CopilotChat/integrations/cmp.lua new file mode 100644 index 00000000..5008395d --- /dev/null +++ b/lua/CopilotChat/integrations/cmp.lua @@ -0,0 +1,45 @@ +local cmp = require('cmp') +local chat = require('CopilotChat') + +local Source = {} + +function Source:get_trigger_characters() + return { '@', '/' } +end + +function Source:complete(params, callback) + local items = {} + local prompts_to_use = chat.prompts() + + if params.completion_context.triggerCharacter == '/' then + for name, _ in pairs(prompts_to_use) do + items[#items + 1] = { + label = '/' .. name, + } + end + else + items[#items + 1] = { + label = '@buffers', + } + + items[#items + 1] = { + label = '@buffer', + } + end + + callback({ items = items }) +end + +local M = {} + +--- Setup the nvim-cmp source for copilot-chat window +function M.setup() + cmp.register_source('copilot-chat', Source) + cmp.setup.filetype('copilot-chat', { + sources = { + { name = 'copilot-chat' }, + }, + }) +end + +return M