forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel.lua
More file actions
61 lines (51 loc) · 1.68 KB
/
panel.lua
File metadata and controls
61 lines (51 loc) · 1.68 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
local util = require("copilot.util")
local panel = {
n_results = 5,
method = "getPanelCompletions",
usecmp = false,
buf = "",
uri = "",
}
local completions = {}
panel.complete = vim.schedule_wrap(function (_, params, callback)
local add_completion = function (result)
local format = require("copilot_cmp.format").format_item
if result then
result.text = result.displayText
local formatted = format(params, result)
completions[formatted.label] = formatted
vim.schedule(function() callback({
isIncomplete = true,
items = vim.tbl_values(completions)
}) end)
end
end
local completed = function ()
vim.schedule(function()
vim.schedule(function() callback({
isIncomplete = false,
items = vim.tbl_values(completions)
}) end)
completions = { isIncomplete = true, items = {} }
end)
end
local completion_params = util.get_completion_params(panel.method)
completion_params.panelId = panel.uri
vim.lsp.buf_request(0, panel.method, completion_params, function () end)
local handlers = require("copilot.handlers")
vim.lsp.handlers["PanelSolution"] = vim.lsp.with(handlers["PanelSolution"], {
callback = add_completion
})
vim.lsp.handlers["PanelSolutionDone"] = vim.lsp.with(handlers["PanelSolutionDone"], {
completed
})
callback({ isIncomplete = true })
end)
function panel.create (opts)
panel = vim.tbl_deep_extend("force", panel, opts or {})
panel.buf = type(panel.uri) == "number" or vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(panel.buf, "copilot:///" .. tostring(panel.buf))
panel.uri = vim.uri_from_bufnr(panel.buf)
return panel
end
return panel