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
38 lines (34 loc) · 968 Bytes
/
Copy pathhandlers.lua
File metadata and controls
38 lines (34 loc) · 968 Bytes
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
local lsp_handlers = {
callbacks = {
["PanelSolution"] = {},
["PanelSolutionsDone"] = {}
},
}
local handlers = {
["PanelSolution"] = function (_, result, _, config)
if result then
for _, callback in pairs(config.callbacks) do
callback(result)
end
end
end,
["PanelSolutionsDone"] = function (_, _, _, config)
for _, callback in pairs(config.callbacks) do
callback()
end
end
}
-- require name so not confusing
lsp_handlers.add_handler_callback = function (handler, fn_name, fn)
lsp_handlers.callbacks[handler][fn_name] = fn
vim.lsp.handlers[handler] = vim.lsp.with(handlers[handler], {
callbacks = lsp_handlers.callbacks[handler]
})
end
lsp_handlers.remove_handler_callback = function (handler, fn_name)
lsp_handlers.callbacks[handler][fn_name] = nil
vim.lsp.handlers[handler] = vim.lsp.with(handlers[handler], {
callbacks = lsp_handlers.callbacks[handler]
})
end
return lsp_handlers