forked from zbirenbaum/copilot-cmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.lua
More file actions
62 lines (49 loc) · 1.32 KB
/
source.lua
File metadata and controls
62 lines (49 loc) · 1.32 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
57
58
59
60
61
62
local source = {
executions = {},
}
function source:get_keyword_pattern()
return '.'
end
source.get_trigger_characters = function()
return {'.'}
end
-- executes before selection
source.resolve = function (self, completion_item, callback)
for _, fn in ipairs(self.executions) do
completion_item = fn(completion_item)
end
callback(completion_item)
end
source.is_available = function(self)
-- client is stopped.
if self.client:is_stopped() or not self.client.name == "copilot" then
return false
end
local get_source_client = function ()
if vim.lsp.get_clients == nil then
return vim.lsp.get_active_clients({
bufnr = vim.api.nvim_get_current_buf(),
id = self.client.id
})
end
return vim.lsp.get_clients({
bufnr = vim.api.nvim_get_current_buf(),
id = self.client.id
})
end
return next(get_source_client()) ~= nil
end
source.execute = function (_, completion_item, callback)
callback(completion_item)
end
source.new = function(client, opts)
local completion_functions = require("copilot_cmp.completion_functions")
local self = setmetatable({
timer = vim.loop.new_timer()
}, { __index = source })
self.client = client
self.request_ids = {}
self.complete = completion_functions.init('getCompletions', opts)
return self
end
return source