forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilot_handler.lua
More file actions
58 lines (53 loc) · 1.76 KB
/
copilot_handler.lua
File metadata and controls
58 lines (53 loc) · 1.76 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
local M = { params = {} }
local util = require("copilot.util")
local panel_handlers = require("copilot.api").panel
M.buf_attach_copilot = function()
if vim.tbl_contains(M.params.ft_disable, vim.bo.filetype) then return end
if not vim.bo.buflisted or not vim.bo.buftype == "" then return end
local client_id = util.find_copilot_client()
local buf_clients = vim.lsp.buf_get_clients(0)
if not buf_clients and client_id or (client_id and not buf_clients[client_id]) then
vim.lsp.buf_attach_client(0, client_id)
end
end
local register_autocmd = function ()
if vim.fn.has("nvim-0.7") > 0 then
vim.api.nvim_create_autocmd({ "BufEnter" }, {
callback = vim.schedule_wrap(M.buf_attach_copilot),
})
else
vim.cmd("au BufEnter * lua vim.schedule(function() require('copilot.copilot_handler').buf_attach_copilot() end)")
end
end
M.merge_server_opts = function (params)
return vim.tbl_deep_extend("force", {
cmd = { "node", require("copilot.util").get_copilot_path(params.plugin_manager_path) },
name = "copilot",
trace = "messages",
root_dir = vim.loop.cwd(),
autostart = true,
on_init = function(_, _)
vim.schedule(M.buf_attach_copilot)
vim.schedule(register_autocmd)
end,
settings = {
advanced = {
listCount = 5, -- #completions for panel
inlineSuggestCount = 1, -- #completions for getCompletions
}
},
handlers = {
["PanelSolution"] = panel_handlers.save,
-- ["PanelSolutionsDone"] = function() end,
}
}, params.server_opts_overrides or {})
end
M.start = function(params)
M.params = params
local client_id = vim.lsp.start_client(M.merge_server_opts(params))
if params.startup_function then
-- params.startup_function()
end
return client_id
end
return M