forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.lua
More file actions
101 lines (92 loc) · 3.09 KB
/
api.lua
File metadata and controls
101 lines (92 loc) · 3.09 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local existing_matches = {}
local util = require("copilot.util")
local panel_printer = require("copilot.print_buf")
local panel_results = {}
local api = {
client_id = nil,
client = nil,
}
api.set_client_info = function (client_id)
api.client_id = client_id
api.client = vim.lsp.get_client_by_id(client_id)
return api.client_id ~= nil
end
api.setup = function ()
local id = util.find_copilot_client()
api.set_client_info(id)
end
local reply_callback = function ()
end
api.panel = {
save = function (_, solution)
if solution and type(solution) == "table" then
panel_results[#panel_results+1] = solution
end
print(#solution)
end,
open = function () require("copilot.panel").init() end,
cmp = function ()
end
-- cmp = function (source, params, callback)
-- if not client then return end
-- local sent, req_id = client.rpc.request("getPanelCompletions", req_params, nil, reply_callback)
-- vim.lsp.buf_request(0, "getPanelCompletions", req_params, function(_, response)
-- -- local timer = vim.loop.new_timer()
-- if response and not vim.tbl_isempty(panel_results) then
-- for i, v in ipairs(panel_results) do
-- print(i)
-- print(v)
-- end
-- end
-- end)
-- end,
-- print = function (_, solutions)
-- if type(solutions) == "table" then
-- panel_printer.print(solutions)
-- end
-- end,
-- timer:start(0, 100, vim.schedule_wrap(function()
-- timer:stop()
-- local entries = source:format_completions(params, panel_results)
-- vim.schedule(function()
-- print(entries)
-- -- callback(entries)
-- panel_results = {}
-- end)
-- end
-- end))
-- cmp = function (source, params, callback)
-- local entries = {}
-- if panel_results then
-- entries = source:format_completions(params, panel_results)
-- vim.schedule(function() callback(entries) end)
-- panel_results = nil
-- else
-- callback({ isIncomplete = true })
-- end
-- end
}
vim.api.nvim_create_user_command("CopilotPanel", function ()
api.panel.open()
end, {})
local function verify_existing (params)
existing_matches[params.context.bufnr] = existing_matches[params.context.bufnr] or {}
existing_matches[params.context.bufnr][params.context.cursor.row] = existing_matches[params.context.bufnr][params.context.cursor.row] or { IsIncomplete = true }
local existing = existing_matches[params.context.bufnr][params.context.cursor.row]
return existing
end
api.complete_cycling = function (source, params, callback)
local existing = verify_existing(params)
local has_complete = false
vim.lsp.buf_request(0, "getCompletionsCycling", util.get_completion_params(), function(_, response)
if response and not vim.tbl_isempty(response.completions) then
existing = vim.tbl_deep_extend("force", existing, source:format_completions(params, response.completions))
has_complete = true
end
vim.schedule(function() callback(existing) end)
end)
if not has_complete then
callback(existing)
end
end
return api