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
56 lines (46 loc) · 1.28 KB
/
Copy pathcmp.lua
File metadata and controls
56 lines (46 loc) · 1.28 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
53
54
55
56
local cmp = require('cmp')
local chat = require('CopilotChat')
local Source = {}
function Source:get_trigger_characters()
return { '@', '/' }
end
function Source:get_keyword_pattern()
return [[\%(@\|/\)\k*]]
end
function Source:complete(params, callback)
local items = {}
local prompts_to_use = chat.prompts()
local prefix = string.lower(params.context.cursor_before_line:sub(params.offset))
local prefix_len = #prefix
local checkAdd = function(word)
if word:lower():sub(1, prefix_len) == prefix then
items[#items + 1] = {
label = word,
kind = cmp.lsp.CompletionItemKind.Keyword,
}
end
end
for name, _ in pairs(prompts_to_use) do
checkAdd('/' .. name)
end
checkAdd('@buffers')
checkAdd('@buffer')
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