-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathinit.lua
More file actions
61 lines (50 loc) · 1.47 KB
/
Copy pathinit.lua
File metadata and controls
61 lines (50 loc) · 1.47 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 source = require("copilot_cmp.source")
local capabilities = require("copilot_cmp.capabilities")
---Registered client and source mapping.
local M = {
client_source_map = {},
registered = false,
default_capabilities = capabilities.default_capabilities,
update_capabilities = capabilities.update_capabilities,
}
local default_opts = {
event = { "InsertEnter", "LspAttach" },
fix_pairs = true,
}
M._on_insert_enter = function(opts)
local find_buf_clients = function()
if vim.lsp.get_clients == nil then
return vim.tbl_filter(function (client)
return client.name == "copilot"
end, vim.lsp.get_active_clients())
end
return vim.lsp.get_clients({
name = "copilot",
bufnr = vim.api.nvim_get_current_buf()
})
end
local cmp = require("cmp")
local clients = find_buf_clients()
if #clients == 0 then
return
end
for _, copilot in ipairs(clients) do
if not M.client_source_map[copilot.id] then
local s = source.new(copilot, opts)
if s:is_available() then
M.client_source_map[copilot.id] = cmp.register_source("copilot", s)
end
end
end
end
M.setup = function(opts)
opts = vim.tbl_deep_extend("force", default_opts, opts or {})
-- just in case someone decides to set event to nil for some reason
local startEvent = opts.event or { "InsertEnter", "LspAttach" }
vim.api.nvim_create_autocmd(startEvent, {
callback = function ()
M._on_insert_enter(opts)
end
})
end
return M