forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmp.lua
More file actions
52 lines (42 loc) · 1.08 KB
/
Copy pathcmp.lua
File metadata and controls
52 lines (42 loc) · 1.08 KB
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
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
---@param completion_item lsp.CompletionItem
---@param callback fun(completion_item: lsp.CompletionItem|nil)
function Source:execute(completion_item, callback)
callback(completion_item)
vim.api.nvim_set_option_value('buflisted', false, { buf = 0 })
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