Skip to content

Commit b71dcea

Browse files
committed
trigger copilot_cmp on attach
1 parent c093aa5 commit b71dcea

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

lua/copilot/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ local M = {}
22

33
local defaults = {
44
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
5+
on_attach = function()
6+
require("copilot_cmp")._on_insert_enter()
7+
end,
58
}
69

710
M.params = {}

lua/copilot/copilot_handler.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ end
1818
local capabilities = vim.lsp.protocol.make_client_capabilities()
1919
capabilities.getCompletions = true
2020

21-
M.start = function(plugin_path)
21+
M.start = function(params)
2222
vim.lsp.start_client({
23-
cmd = { require("copilot.util").get_copilot_path(plugin_path) },
23+
cmd = { require("copilot.util").get_copilot_path(params.plugin_manager_path) },
2424
cmd_env = {
2525
["GITHUB_USER"] = user_data.user,
2626
["GITHUB_TOKEN"] = user_data.token,
@@ -52,6 +52,11 @@ M.start = function(plugin_path)
5252
vim.cmd("au BufEnter * lua require('copilot.util').attach_copilot()")
5353
end
5454
end,
55+
on_attach = function()
56+
vim.schedule(function()
57+
params.on_attach()
58+
end)
59+
end,
5560
})
5661
end
5762

lua/copilot/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local M = {}
44
M.setup = function(params)
55
config.setup(params)
66
config.params.plugin_manager_path = vim.fn.expand(config.params.plugin_manager_path) -- resolve wildcard and variable containing paths
7-
require("copilot.copilot_handler").start(config.params.plugin_manager_path)
7+
require("copilot.copilot_handler").start(config.params)
88
end
99

1010
return M

lua/copilot/util.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ local get_relfile = function()
1111
return file
1212
end
1313

14-
M.find_copilot_client = function ()
14+
M.find_copilot_client = function()
1515
for _, client in ipairs(vim.lsp.get_active_clients()) do
1616
if client.name == "copilot" then
1717
return client.id
1818
end
1919
end
20-
print("Copilot not started!")
2120
end
2221

23-
M.attach_copilot = function ()
22+
M.find_copilot_buf_client = function()
23+
for _, client in ipairs(vim.lsp.buf_get_clients(0)) do
24+
if client.name == "copilot" then
25+
return client.id
26+
end
27+
end
28+
end
29+
30+
M.attach_copilot = function()
2431
local client_id = require("copilot.util").find_copilot_client()
2532
if not vim.lsp.buf_get_clients(0)[client_id] then
2633
vim.lsp.buf_attach_client(0, client_id)

0 commit comments

Comments
 (0)