Skip to content

Commit

Permalink
feat: Add nvim-cmp integration
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam committed May 29, 2024
1 parent c21c87d commit c3e8c23
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,30 @@ Requires [fzf-lua](https://github.com/ibhagwan/fzf-lua) plugin to be installed.

</details>

<details>
<summary>nvim-cmp integration</summary>

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 <tab> 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)

</details>

## Roadmap (Wishlist)

- Use indexed vector database with current workspace for better context selection
Expand Down
45 changes: 45 additions & 0 deletions lua/CopilotChat/integrations/cmp.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c3e8c23

Please sign in to comment.