forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.lua
More file actions
45 lines (39 loc) · 1.69 KB
/
handlers.lua
File metadata and controls
45 lines (39 loc) · 1.69 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
local M = {
callback = {
PanelSolution = {},
PanelSolutionsDone = {},
},
handlers = {},
}
---@alias copilot_panel_solution_data { panelId: string, completionText: string, displayText: string, range: { ['end']: { character: integer, line: integer }, start: { character: integer, line: integer } }, score: number, solutionId: string }
---@alias copilot_panel_on_solution_handler fun(result: copilot_panel_solution_data): nil
---@alias copilot_panel_solutions_done_data { panelId: string, status: 'OK'|'Error', message?: string }
---@alias copilot_panel_on_solutions_done_handler fun(result: copilot_panel_solutions_done_data): nil
M.handlers = {
---@param result copilot_panel_solution_data
PanelSolution = function(_, result)
if M.callback.PanelSolution[result.panelId] then
M.callback.PanelSolution[result.panelId](result)
end
end,
---@param result copilot_panel_solutions_done_data
PanelSolutionsDone = function(_, result)
if M.callback.PanelSolutionsDone[result.panelId] then
M.callback.PanelSolutionsDone[result.panelId](result)
end
end,
}
---@param panelId string
---@param handlers { on_solution: copilot_panel_on_solution_handler, on_solutions_done: copilot_panel_on_solutions_done_handler }
function M.register_panel_handlers(panelId, handlers)
assert(type(panelId) == "string", "missing panelId")
M.callback.PanelSolution[panelId] = handlers.on_solution
M.callback.PanelSolutionsDone[panelId] = handlers.on_solutions_done
end
---@param panelId string
function M.unregister_panel_handlers(panelId)
assert(type(panelId) == "string", "missing panelId")
M.callback.PanelSolution[panelId] = nil
M.callback.PanelSolutionsDone[panelId] = nil
end
return M